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