Sunday 27 November 2011

C Program For Simple Link List


#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
   struct list
   {
     int data;
struct list * netxt;
   };
void main()
 {
   street list*node,*start,*temp;
   start=node=temp=null;
   int ch;
   do{
       printf("1.add 2.display 3.exit");
  scanf("%d",& ch);
  if(ch == 1)
   {
 node=(struct list*);
 scanf("%d",&node->data);
  if(start == null)
   {
 start = node;
 start->next = null;
}
  else
    temp = start;
while(temp->next!=null)
{
 temp= temp->next;
}
temp->next=node;
node->next=null;
}
  if(ch == 2)
   {
 for(temp = start;temp!=null;temp->next)
  {
    printf("%d",temp->data);
  }
}
  if(ch == 3)
   exit(0);
}while(1);
getch();

}


No comments:

Post a Comment