Advertisement
J00ker

Untitled

Mar 4th, 2015
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <climits>
  4. #define Nmax 1000
  5.  
  6. using namespace std;
  7.  
  8. struct Stiva
  9. {
  10. int st[Nmax];
  11. int top;
  12.  
  13. void Init()
  14. {
  15. top = -1;
  16. }
  17.  
  18. int Empty()
  19. {
  20. if(top == -1) return 1;
  21. return 0;
  22. }
  23.  
  24. int Full()
  25. {
  26. if(top == Nmax - 1) return 1;
  27. return 0;
  28. }
  29.  
  30. void Push(int x)
  31. {
  32. if(Full()) cout << "Stack Overflow!";
  33. else st[++top] = x;
  34. }
  35.  
  36. void Pop()
  37. {
  38. if(!Empty()) top--;
  39. }
  40.  
  41. int Top()
  42. {
  43. return st[top];
  44. }
  45.  
  46. int Elem()
  47. {
  48. return top+1;
  49. }
  50.  
  51. int Minim()
  52. {
  53. int m = INT_MAX;
  54. for(int i = 0; i <= top; i++)
  55. if(st[i] < m) m = st[i];
  56. return m;
  57. }
  58. };
  59.  
  60. int main()
  61. {
  62. int n, op;
  63. Stiva st;
  64.  
  65. ifstream fin("stiva.in");
  66. ofstream fout("stiva.out");
  67.  
  68. fin >> n;
  69. st.Init();
  70.  
  71. for(int i = 1; i <= n; i++)
  72. {
  73. fin >> op;
  74. if(op == 1)
  75. {
  76. fin >> op;
  77. st.Push(op);
  78. }
  79. else if(op == 2)
  80. {
  81. if(st.Elem() > 0) fout << st.Top() << "\n";
  82. else fout << "Eroare 2!\n";
  83. }
  84. else if(op == 3) st.Pop();
  85. else if(op == 4) fout << st.Elem() << "\n";
  86. else fout << st.Minim() << "\n";
  87. }
  88.  
  89. fin.close();
  90. fout.close();
  91.  
  92. return 0;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement