Advertisement
Guest User

Untitled

a guest
Jul 25th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. #include<iostream>
  2. #define STACK_OVERFLOW 404
  3. #define STACK_UNDERFLOW 401
  4.  
  5. using namespace std;
  6.  
  7. const int max = 20;
  8.  
  9. struct Stack
  10. {
  11. int mas[max];
  12. int size;
  13. };
  14.  
  15. void push(Stack& stack, int value)
  16. {
  17. if (stack.size >= max)
  18. {
  19. exit(STACK_OVERFLOW);
  20. }
  21. stack.mas[stack.size] = value;
  22. stack.size++;
  23. }
  24. int pop(Stack& stack)
  25. {
  26. if (stack.size == 0)
  27. {
  28. exit(STACK_UNDERFLOW);
  29. }
  30. stack.mas[stack.size - 1];
  31. stack.size--;
  32. }
  33.  
  34. void print(Stack& stack)
  35. {
  36. for (int i = 0; i < stack.size; i++)
  37. {
  38. cout << stack.mas[i] << " ";
  39. }
  40. cout << endl;
  41.  
  42. }
  43.  
  44. int main()
  45. {
  46.  
  47.  
  48. Stack s;
  49. s.size = 0;
  50.  
  51. push(s, 5);
  52. push(s, -3);
  53. push(s, 23);
  54. push(s, 12);
  55. print(s);
  56.  
  57. pop(s);
  58. print(s);
  59.  
  60. pop(s);
  61. print(s);
  62.  
  63. pop(s);
  64. print(s);
  65.  
  66. cin.ignore(2, '\n');
  67. return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement