juyana

stack class

Jun 4th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. class node
  2. {
  3. public:
  4. int data,sizee=0;
  5. node *next;
  6.  
  7. node *head=NULL,*temp=NULL;
  8.  
  9. void Insert(int x)
  10. {
  11. sizee++;
  12. node *ptr;
  13. ptr=new node();
  14. ptr->data=x;
  15. ptr->next=NULL;
  16.  
  17. if(head==NULL)
  18. {
  19. head=ptr;
  20. temp=head;
  21. }
  22.  
  23. else
  24. {
  25. temp->next=ptr;
  26. temp=ptr;
  27. }
  28. }
  29. int Top()
  30. {
  31. if(head==NULL) return -1;
  32. return head->data;
  33. }
  34. void pop()
  35. {
  36. node *srt=head;
  37. head=srt->next;
  38. }
  39.  
  40. int Size()
  41. {
  42. return sizee;
  43. }
  44. };
  45.  
  46.  
  47. class stackk
  48. {
  49. public:
  50. node *top=NULL;
  51.  
  52. void Push(int x)
  53. {
  54. node *ptr;
  55. ptr=new node();
  56. ptr->data=x;
  57. ptr->next=top;
  58. top=ptr;
  59. }
  60. int Top()
  61. {
  62. if(top==NULL) return -1;
  63. return top->data;
  64. }
  65. void pop()
  66. {
  67. top=top->next;
  68. }
  69. };
Advertisement
Add Comment
Please, Sign In to add comment