bipo143

Quewe lab 08 tarik

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