Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- class Stek {
- int top;
- int* stackElems;
- int size;
- public:
- ~Stek() {
- delete[] stackElems;
- }
- bool isEmpty() {
- return (this->top < 0);
- }
- int topElem()
- {
- //ne brise ga
- if (this->top < 0)
- throw "Underflow";
- int tmp = stackElems[top];
- return tmp;
- }
- Stek(int asize)
- {
- top = -1;
- stackElems = new int[asize];
- this->size = asize;
- }
- void push(int a)
- {
- if (top == size-1)
- throw "Overflow!";
- top = top + 1;
- stackElems[top] = a;
- }
- int pop()
- {
- if (top < 0)
- throw "Underflow";
- int tmp = stackElems[top];
- top = top - 1;
- return tmp;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement