Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class stack
- {
- private:
- int arr[5];
- int top;
- public:
- stack()
- {
- top = -1;
- }
- void push ( int v )
- {
- if ( top == 4 )
- { cout << "stack is full" << endl; }
- else
- {
- arr[++top] = v;
- cout << "data push successfully" << endl;
- }
- }
- int pop()
- {
- if ( top == -1 )
- {
- cout << "stack empty" << endl;
- return 0;
- }
- else
- { return arr[top--]; }
- }
- };
- int main()
- {
- stack s;
- s.push ( 10 );
- cout << s.pop() << endl;
- return 0;
- }
Add Comment
Please, Sign In to add comment