god! it’s been 1 hour..


please someone help how to construct a sparse matrix with linked lists.

Advertisements

One thought on “god! it’s been 1 hour..

  1. oh i got it, i just have to make a tweak

    --- Deletions to the program
    +++ Additions to the program
    @@ -17,6 +17,7 @@
     #define sparsetype int /* Type of Sparse matrix */
     #define readsparele(x) scanf("%d",&(x))
     
    +#define RMAX 1000
     typedef struct sparsele
     {
     	sparsetype value;
    @@ -61,8 +62,8 @@
     sparse* readmatrix()
     {
     	sparse* mat;
    -	sparsele *temp,*rpon,*cpon;
    -	headtail *riterator, *citerator;
    +	sparsele *temp,*rpon,*cpon[RMAX];
    +	headtail *riterator, *citerator,*t;
     	int r,c,i,j;
     	sparsetype n;
     	scanf("%d%d", &r, &c);
    @@ -71,7 +72,12 @@
     	riterator=mat->rowit;
     	citerator=mat->colit;
     	rpon=riterator->pin;
    -	cpon=citerator->pin;
    +	t=citerator;
    +	for (i = 0; i < c; ++i)
    +	{
    +		cpon[i]=t->pin;
    +		t=t->next;
    +	}
     	for (i = 0; i < r; ++i)
     	{
     		for (j = 0; j < c; ++j)
    @@ -82,7 +88,9 @@
     				temp=(sparsele*)malloc(sizeof(sparsele));
     				temp->value=n;
     				rpon=temp;
    +				cpon[j]=temp;
     				rpon=temp->rnext;
    +				cpon[j]=temp->cnext;
     			}
     		}
     	}
    
    

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s