Advertisement
apl-mhd

LINKED LIST MENU SIR

Mar 7th, 2017
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.23 KB | None | 0 0
  1.  
  2. #include<stdio.h>
  3. struct list
  4. {
  5.     int data;
  6.     struct list *next;
  7. };
  8.  
  9. typedef struct list node;
  10.  
  11. void display(node *start)
  12. {
  13.     node *temp;
  14.     temp=start;
  15.     while(temp!=NULL)
  16.     {
  17.         printf("%d ",temp->data);
  18.         temp=temp->next;
  19.     }
  20. }
  21. node *insertion(node *start,int item)
  22. {
  23.     node *temp;
  24.     if(start==NULL)
  25.     {
  26.         start=new node();
  27.         start->next=NULL;
  28.         start->data=item;
  29.     }
  30.     else if(start->data>=item)
  31.     {
  32.         temp=new node();
  33.         temp->data=item;
  34.         temp->next = start;
  35.         start = temp;
  36.  
  37.     }
  38.    
  39.    
  40.  
  41. return start;
  42. }
  43.  void showMenu()
  44.  {
  45.      printf("\n1.Insert\n2.Delete\n3.Exit");
  46.  
  47.  }
  48.  
  49. int main()
  50. {
  51.     node *start=NULL;
  52.     int choise,item,i=1;
  53.     do{
  54.         showMenu();
  55.         printf("\n");
  56.         printf("Enter Choise:");
  57.         scanf("%d",&choise);
  58.         if(choise==1)
  59.         {
  60.             printf("Enter Item:");
  61.             scanf("%d",&item);
  62.             start=insertion(start,item);
  63.             display(start);
  64.  
  65.  
  66.         }
  67.         else if(choise==2)
  68.         {
  69.  
  70.         }
  71.         else
  72.         {
  73.             i=0;
  74.         }
  75.     }
  76.     while(i);
  77.  
  78.  
  79.  
  80.    // display(start);
  81.   return 0;
  82.  
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement