I was thinking about 2-D arrays and memory, there it stroke me Sparse Matrix, a relatively efficient way to do so. Then why not develop it, there it started rolling:
Source Code
Mapping of nodes, for easy understandibility
Things done to create a node:
__________________
| | |
| | |
| 1 | 2 |
| | |
|_________|______|
| 3 | 4 |
|_________|______|
1. template <class T>class node :: <T> data. //Template
2. template <class T>class node :: node <T> * hnode. //hnode stands for horizontal link to the node
3. template <class T>class node :: node <T> * vnode. //vnode stands for vertical link to the node
4. template <class T>class node :: short int num data. //For tracking node positions
About the code:
sparse is defined as a generic class having
Data variables:
Member Functions:
int insertion ( case 2 , node <T>* a , int pv , int ph )
int insertion ( case 3 , node <T>* a , int pv , int ph )
int insertion ( case 4 , node <T>* a , int pv , int ph )
int index_return( int ret = 0 , node <T> * a)
int index_return( int ret = 1 , node <T> * a)
More recent definitions to the code
/* incase i = insertion ( casei )
*
* incase 1: when at both positions root->vnode[pv].hnode and
* root->hnode[ph].vnode, don't have any node associated with
* them
*
* incase 2: when root->vnode[pv].hnode is occupied and
* root->hnode[ph].vnode is free
*
* incase 3: when root->hnode[ph].vnode is occupied and
* root->vnode[pv].hnode is free
*
* incase 4: when both root->hnode[ph].vnode and
* root->vnode[pv].hnode are occupied
*
* index_return(0, ... ) returns the current vertical position
* ( assumed that the mxn matrix created is similar to a
* a standing grid )
*
* index_return( 1 , ... ) returns the horizontal position of the
* node in the matrix grid
*/
Please suggest me more functions which I may write for increased usability.
Source Code
Mapping of nodes, for easy understandibility
Things done to create a node:
__________________
| | |
| | |
| 1 | 2 |
| | |
|_________|______|
| 3 | 4 |
|_________|______|
1. template <class T>class node :: <T> data. //Template
2. template <class T>class node :: node <T> * hnode. //hnode stands for horizontal link to the node
3. template <class T>class node :: node <T> * vnode. //vnode stands for vertical link to the node
4. template <class T>class node :: short int num data. //For tracking node positions
About the code:
sparse is defined as a generic class having
Data variables:
public:
node <T>* root;
private:
node <T>* temp;
int m, n; // to define the maximum size of the sparse matrix
Member Functions:
public:
sparse();//Constructer
void insert(int case, T a, int posva,int posha);//for insertion
void display( void ); //lots of bugs to be fixed in this function
private:
int insertion ( case 1 , node <T>* a , int pv , int ph )int insertion ( case 2 , node <T>* a , int pv , int ph )
int insertion ( case 3 , node <T>* a , int pv , int ph )
int insertion ( case 4 , node <T>* a , int pv , int ph )
int index_return( int ret = 0 , node <T> * a)
int index_return( int ret = 1 , node <T> * a)
More recent definitions to the code
/* incase i = insertion ( casei )
*
* incase 1: when at both positions root->vnode[pv].hnode and
* root->hnode[ph].vnode, don't have any node associated with
* them
*
* incase 2: when root->vnode[pv].hnode is occupied and
* root->hnode[ph].vnode is free
*
* incase 3: when root->hnode[ph].vnode is occupied and
* root->vnode[pv].hnode is free
*
* incase 4: when both root->hnode[ph].vnode and
* root->vnode[pv].hnode are occupied
*
* index_return(0, ... ) returns the current vertical position
* ( assumed that the mxn matrix created is similar to a
* a standing grid )
*
* index_return( 1 , ... ) returns the horizontal position of the
* node in the matrix grid
*/
Please suggest me more functions which I may write for increased usability.
No comments:
Post a Comment