bipo143

data lab 20\03\17

Mar 20th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. #include<stdlib.h>
  2. struct node
  3. {
  4. int a;
  5. struct node *p;
  6. };
  7.  
  8. void Insertion_Last(struct node *head, int value);
  9. void Display(struct node *head);
  10.  
  11. int main()
  12. {
  13. int n,i,c,v,p,q;
  14. struct node *list;
  15. list=(struct node *) malloc(1*sizeof(struct node));
  16. list->a=0;
  17. list->p=NULL;
  18.  
  19. printf("\n----------Menu-----------\n");
  20. printf("\nPress 0 for quit\n");
  21. printf("\nPress 1 for insertion at last position\n");
  22. printf("\nPress 2 for insertion at specific position\n");
  23. printf("\nPress 3 for display\n");
  24. printf("\nPress 4 for deletion at specific position\n");
  25. printf("\nPress 5 for counting total node\n");
  26. printf("\nPress 2 for linear search\n");
  27.  
  28. printf("\nEnter your choice:\n");
  29. scanf("%d",&c);while(1)
  30. {
  31. switch(c)
  32. {
  33. case 0: exit(0);
  34. break;
  35.  
  36. case 1: printf("\nchoice = Insertion at last position\n");
  37. printf("\n Enter new value \n");
  38. scanf("%d",&v);
  39. Insertion_Last(list,v);
  40. break;
  41.  
  42. case 3: printf("\nchoice = Display\n");
  43. if(list->p!=NULL)
  44. Display(list);
  45. else
  46. printf("\nThe list is empty\n");
  47. break;
  48.  
  49. default: printf("\n\n Wrong position\n");
  50.  
  51. }
  52.  
  53. }
  54. }
  55.  
  56.  
  57. void Insertion_Last(struct node *head, int value)
  58. {
  59. struct node *temp;
  60. while(head->p!=NULL)
  61. head=head->p;
  62.  
  63. temp=(struct node *) malloc(1*sizeof(struct node));
  64. temp->a=value;
  65. temp->p=NULL;
  66. head->p=temp;
  67. }
  68. void Display(struct node *head)
  69. {
  70. while(head->p!=NULL)
  71. {
  72. printf("\t->%d->",head->p->a);
  73. head=head->p;
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment