-
Notifications
You must be signed in to change notification settings - Fork 0
/
50.cpp
58 lines (49 loc) · 962 Bytes
/
50.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include<iostream>
using namespace std;
const int MAX = 4;
class Stack
{
protected:
int st[MAX];
int top;
public:
Stack() { top = 0; }
void push(int var) { st[++top] = var; }
int pop() { return st[top--]; }
};
class Stack2: public Stack
{
public:
void push(int var)
{
if(top < MAX)
Stack::push(var);
else
cout << "\nError Stack is Full\n" << endl;
}
int pop()
{
if(top > 0)
return Stack::pop();
else
{
cout << "\nError Stack is Empty\n" << endl;
return -1;
}
}
};
int main(void)
{
Stack2 s1;
Stack s;
s.pop();
s.push(23);
s1.push(11);
s1.push(22);
s1.push(33);
cout << endl << s1.pop();
cout << endl << s1.pop();
cout << endl << s1.pop();
cout << endl << s1.pop();
return 0;
}