bipo143

pus ,pos Full code 01/04

Apr 1st, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3.  
  4. struct node
  5. {
  6. int data;
  7. struct node * link;
  8. };
  9.  
  10. void Push(int vv);
  11. void Pop ();
  12. void Display();
  13. void Count();
  14. struct node* top= NULL,*temp;
  15. int main()
  16. {
  17. int c,v;
  18. while(1)
  19. {
  20. printf("\-------Menu-----\n");
  21. printf("\n Press 1 for Push\n");
  22. printf("\n Press 2 for Pop\n");
  23. printf("\n Press 3 for Display\n");
  24. printf("\n Press 4 for Count\n");
  25. printf("\n Press 5 Quit\n");
  26.  
  27. printf("\n enter your choice\n");
  28. scanf("%d",&c);
  29. switch(c)
  30. {
  31. case 1:printf("\n choice = Push\n");
  32. printf("\n Enter value for insertion \n");
  33. scanf("%d",&v);
  34. Push(v);
  35. break;
  36.  
  37. case 2:printf("\n choice = Pop\n");
  38. if(top!=NULL)
  39. Pop();
  40. else
  41. printf("\n no data to delete\n");
  42. break;
  43.  
  44. case 3:printf("\n choice = Display\n");
  45. if(top!=NULL)
  46. Display();
  47. else
  48. printf("\n the stack is empty\n");
  49. break;
  50.  
  51. case 4:printf("\n choice = Count\n");
  52. Count();
  53. break;
  54.  
  55. case 5: exit(0);
  56. break;
  57.  
  58.  
  59. }
  60.  
  61.  
  62. }
  63. }
  64.  
  65. void Push(int vv)
  66. {
  67. temp=(struct node *)malloc(1* sizeof(struct node));
  68. temp->data=vv;
  69. temp->link=top;
  70. top=temp;
  71. }
  72.  
  73. void Display()
  74. {
  75. temp=top;
  76. while(temp!=NULL)
  77. {
  78. printf("\n%d\n",temp->data);
  79. temp=temp->link;
  80. }
  81. }
  82.  
  83. void Pop ()
  84. {
  85. temp=top;
  86. top=temp->link;
  87. printf("\n the deleted node= %d\n",temp->data);
  88. free(temp);
  89. }
  90.  
  91. void Count()
  92. {
  93. int n=0;
  94. temp=top;
  95. while(temp!=NULL)
  96. {
  97. n=n+1;
  98. temp=temp->link;
  99. }
  100. printf("\n total value=%d\n",n);
  101. }
Advertisement
Add Comment
Please, Sign In to add comment