Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Stiva
- {
- private:
- int varf=0;
- struct stiva{int X, Max=0;}S[100001];
- public:
- // depune valoarea x in stiva
- void Push(int x)
- {
- S[++varf].X=x;
- if(varf==1) S[varf].Max=x;
- else
- if(x>S[varf-1].Max) S[varf].Max=x;
- else S[varf].Max=S[varf-1].Max;
- }
- // elimina un element din stiva daca stiva nu e vida
- void Pop()
- {
- if(!Empty())varf--;
- }
- // returneaza varful stivei
- // daca stiva este vida, returneaza -1
- int Top()
- {
- if(Empty()) return -1;
- return S[varf].X;
- }
- // returneaza valoarea maxima din stiva
- // daca stiva este vida, returneaza -1
- int Max()
- {
- if(Empty()) return -1;
- return S[varf].Max;
- }
- // returneaza 1 daca stiva este vida
- // returneaza 0 daca stiva nu e vida
- int Empty()
- {
- if(varf>0) return 0;
- return 1;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement