bipo143

push 01\04

Apr 1st, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 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 Display();
  12. struct node* top= NULL,*temp;
  13. int main()
  14. {
  15. int c,v;
  16. while(1)
  17. {
  18. printf("\-------Menu-----\n");
  19. printf("\n Press 1 for Push\n");
  20. printf("\n Press 2 for Pop\n");
  21. printf("\n Press 3 for Display\n");
  22. printf("\n Press 4 for Count\n");
  23. printf("\n Press 5 Quit\n");
  24.  
  25. printf("\n enter your choice\n");
  26. scanf("%d",&c);
  27. switch(c)
  28. {
  29. case 1:printf("\n choice = Push\n");
  30. printf("\n Enter value for insertion \n");
  31. scanf("%d",&v);
  32. Push(v);
  33. break;
  34.  
  35. case 3:printf("\n choice = Display\n");
  36. if(top!=NULL)
  37. Display();
  38. else
  39. printf("\n the stack is empty\n");
  40. break;
  41.  
  42.  
  43. }
  44.  
  45.  
  46. }
  47. }
  48.  
  49. void Push(int vv)
  50. {
  51. temp=(struct node *)malloc(1* sizeof(struct node));
  52. temp->data=vv;
  53. temp->link=top;
  54. top=temp;
  55. }
  56.  
  57. void Display()
  58. {
  59. temp=top;
  60. while(temp!=NULL)
  61. {
  62. printf("\n%d\n",temp->data);
  63. temp=temp->link;
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment