This is how my program is but it doesn't print the full list only node's data which entered last.I couldn't understand what is the problem in linking or not :
basic Structure of node
struct node
{
int data;
struct node *link;
};
defining header as start of link list :
struct node *header;
Functions for Insert and print :
void insertFront_sl();
void print_sl();
The main function :
void main()
{
clrscr();
header=(struct node *)malloc(sizeof(struct node));
header->link=NULL;
header->data=NULL;
insertFront_sl();
insertFront_sl();
insertFront_sl();
insertFront_sl();
print_sl();
getch();
}
void insertFront_sl(){
struct node *temp;
int x;
temp=(struct node *)malloc(sizeof(struct node));
if(temp==NULL)
{
printf("\nMeM0rY Insufficient ..");
}
else
{
printf("\nGot New Node \nNow Insert Data Into Node : ");
scanf("%d",&x);
temp->data=x;
header->link=temp;
}
}
void print_sl(){
struct node *ptr;
ptr=header;
while(ptr->link !=NULL)
{
ptr=ptr->link;
printf("%d\t",ptr->data);
}
}