-
Notifications
You must be signed in to change notification settings - Fork 1
/
example_stack1.cpp
70 lines (63 loc) · 925 Bytes
/
example_stack1.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
59
60
61
62
63
64
65
66
67
68
69
70
// Online IDE - Code Editor, Compiler, Interpreter
#include<iostream>
using namespace std;
class mystack
{
private:
int *ptr;
int size;
int top;
public:
mystack(int sz)
{
size = sz;
top = -1;
ptr = new int(size);
}
void push(int x);
int pop();
};
void mystack :: push(int x)
{
if(top == size - 1)
{
cout<<"Full"<<endl;
}
else
{
top += 1;
ptr[top] = x;
}
}
int mystack :: pop()
{
if(top == -1)
{
cout<<"Empty"<<endl;
}
else
{
int x = ptr[top];
top -= 1;
cout<< x<<endl;
}
return 1;
}
int main()
{
mystack s(5);
int i = 0;
s.push(i++);
s.push(i++);
s.push(i++);
s.push(i++);
s.push(i++);
s.push(i++);
s.push(i++);
s.pop();
s.pop();
s.pop();
s.pop();
s.pop();
return 0;
}