Advertisement
Guest User

Untitled

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