Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Stack
- {
- private:
- int * Arr;
- int TOP, SIZE;
- public:
- Stack(unsigned int _size = 15)
- {
- Arr = new int[15];
- SIZE = _size;
- TOP = 0 ;
- }
- bool Push(int value)
- {
- if (TOP<SIZE)
- {
- Arr[TOP++]= value;
- return true;
- } else
- return false;
- }
- bool pop(int & val)
- {
- if (TOP-1 >= 0)
- {
- val = Arr[TOP--];
- return true;
- } else
- return false;
- }
- };
- int main()
- {
- Stack T;
- for (int i =0 ; i < 15; i++)
- {
- if (T.Push(i))
- cout << i << endl;
- else
- cout << "No" << endl;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment