Saturday, August 20, 2011

How to create linked list.

//How to create linked list.
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node *next;
};

main()
{
struct node *lst,*p,*start;
int i,n;
start=NULL;
lst=NULL;
printf("Enter the elements you want in your linked list :");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
 p=(struct node *)malloc(sizeof(struct node));
 printf("Enter the %d element :",i);
 scanf("%d",&(p->data));
 p->next=NULL;
 if(start==NULL)
    start=p;
 else
   lst->next=p;
  lst=p;
}
p=start;
printf("Entered linked list is :");
while(p!=NULL)
{
printf(" %d\n ",p->data);
p=p->next;
}
}

Previous Next Home
0 Comments
Comments

Leave a Comment

:)) ;)) ;;) :D ;) :p :(( :) :( :X =(( :-o :-/ :-* :| 8-} :)] ~x( :-t b-( :-L x( =))

Twitter Delicious Facebook Favorites More