Advertisement
Guest User

Untitled

a guest
Jun 24th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. #include<iostream>
  2.  
  3. using namespace std;
  4.  
  5. struct Node
  6. {
  7. int data;
  8. Node* next;
  9. };
  10.  
  11. Node* tos = NULL;
  12.  
  13. void isEmpty();
  14. void push(int x);
  15. void pop();
  16. void top();
  17.  
  18. int main(){
  19. isEmpty();
  20. push(1);
  21. push(2);
  22. top();
  23. pop();
  24. isEmpty();
  25. top();
  26.  
  27. return 0;
  28. }
  29.  
  30. void isEmpty(){
  31. if(tos==NULL){
  32. cout <<"Stack is empty"<<endl;
  33. return;
  34. }
  35. cout <<"Stack is not empty"<<endl;
  36.  
  37. }
  38.  
  39. void push(int x){
  40. Node* temp = new Node();
  41. temp->data = x;
  42. temp->next = tos;
  43. tos = temp;
  44. }
  45.  
  46. void pop(){
  47. if(tos==NULL){
  48. cout <<"Stack is empty"<<endl;
  49. return;
  50. }
  51. Node* del = tos;
  52. tos = tos->next;
  53. delete del;
  54. }
  55.  
  56. void top(){
  57. if(tos==NULL){
  58. cout <<"Stack is empty"<<endl;
  59. return;
  60. }
  61. cout << tos->data << endl;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement