/************************ author ' s email:wardseptember@gmail.com sparse matrix representation of the cross-linked table ************************/#include
<iostream> using namespace std;
#define MAXSIZE 4//Common node definition typedef struct OLNODE {int row, col;
struct Olnode *right, *down;
float Val;
}olnode,*node;
The head node structure defines the typedef struct {Olnode *rhead, *chead;
int m, n, K;
}crosslist;
int Initmatrix (crosslist *m);
int Createcrosslistmat (float a[][maxsize], int m, int n, int k, crosslist *m);
int main () {float A[][maxsize] = {{0,0,0,1}, {0,0,3,2}, {1,0,0,0}, {0,2,0,0}};
int m, n, K;
m = n = maxSize;
K = 5;
Crosslist M;
Initmatrix (&M);
cout << "Elements in the cross-linked list are:" << Endl;
Createcrosslistmat (A, M, N, K, &m);
return 0;
} int Initmatrix (Crosslist *m) {(*m). Rhead = (*m). Chead = NULL;
(*m). K = (*m). M = (*m). N = 0;
return 1;
} int Createcrosslistmat (float a[][maxsize], int m, int n, int k, crosslist *m) {if (*m). Rhead) Free ((*m). Rhead);
if ((*m). Chead) Free ((*m). Chead); (*m). m = m;
(*m). N = n;
(*m). K = k; if (! (
(*m). Rhead = (Olnode *) malloc (sizeof (Olnode) *m))) return 0; if (! (
(*m). Chead = (Olnode *) malloc (sizeof (Olnode) *n))) return 0;
for (int i = 0; i < m; ++i) {(*m). Rhead[i].right = NULL;
(*m). Rhead[i].down = NULL;
} for (int i = 0; i < n; ++i) {(*m). Chead[i].right = NULL;
(*m). Chead[i].down = NULL;
}//Create a list of auxiliary pointers array Olnode *temp_r[maxsize];
for (int j = 0; J < N; ++j) temp_r[j] = & ((*m). Chead[j]);
for (int i = 0; i < m; ++i) {Olnode *c = & ((*m). Rhead[i]);
for (int j = 0; J < N; ++j) {if (a[i][j]! = 0) {Olnode *p = (olnode*) malloc (sizeof (Olnode));
P->row = i;
P->col = j;
P->val = A[i][j];
P->down = NULL;
P->right = NULL;
C->right = p;
c = P;
Temp_r[j]->down = p;
TEMP_R[J] = p;
cout << p->val<< ' t ';
}}} cout << Endl;
return 1; }