#include<stdio.h>
#include<stdlib.h>
struct Node
{
int col;
int data;
struct Node *next;
};
void insert(struct Node *p, int clm, int value)
{
if(p==NULL)
{
struct Node *t;
t=(struct Node *)malloc(sizeof(struct Node));
t->next=NULL;
t->col=clm;
t->data=value;
p=t;
}else
{
struct Node *temp,*t;
temp=p;
while(temp->next!=NULL)
{
temp=temp->next;
}
t=(struct Node *)malloc(sizeof(struct Node));
t->data=value;
t->col=clm;
t->next=NULL;
temp->next=t;
}
}
void Display(struct Node *p[])
{
for(int i=0;i<5;i++)
{
struct Node *t;
t=p[i];
for(int j=0;j<5;j++)
{
if(t!= NULL)
{
if(t->col==j)
{
printf("%d\t",t->data);
t=t->next;
}
}else
{
printf("%d\t",'0');
}
}
printf("\n");
}
}
void main()
{
struct Node *a[5]={};
insert(a[0],0,1);
insert(a[0],1,1);
insert(a[1],1,1);
insert(a[2],2,1);
insert(a[3],3,1);
insert(a[4],4,1);
Display(a);
}
This is code to store sparse matrix in the form of linked list. for this purpose i have created a function to insert elements in linked list. But the changes made inside function does not reflect in actual linked list here for struct Node *a[0] , i have created a link, so it shuld not be NULL now , but when i try to add another link it shows NULL