Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <climits>
- #define Nmax 1000
- using namespace std;
- struct Stiva
- {
- int st[Nmax];
- int top;
- void Init()
- {
- top = -1;
- }
- int Empty()
- {
- if(top == -1) return 1;
- return 0;
- }
- int Full()
- {
- if(top == Nmax - 1) return 1;
- return 0;
- }
- void Push(int x)
- {
- if(Full()) cout << "Stack Overflow!";
- else st[++top] = x;
- }
- void Pop()
- {
- if(!Empty()) top--;
- }
- int Top()
- {
- return st[top];
- }
- int Elem()
- {
- return top+1;
- }
- int Minim()
- {
- int m = INT_MAX;
- for(int i = 0; i <= top; i++)
- if(st[i] < m) m = st[i];
- return m;
- }
- };
- int main()
- {
- int n, op;
- Stiva st;
- ifstream fin("stiva.in");
- ofstream fout("stiva.out");
- fin >> n;
- st.Init();
- for(int i = 1; i <= n; i++)
- {
- fin >> op;
- if(op == 1)
- {
- fin >> op;
- st.Push(op);
- }
- else if(op == 2)
- {
- if(st.Elem() > 0) fout << st.Top() << "\n";
- else fout << "Eroare 2!\n";
- }
- else if(op == 3) st.Pop();
- else if(op == 4) fout << st.Elem() << "\n";
- else fout << st.Minim() << "\n";
- }
- fin.close();
- fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement