-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathstack 1.cpp
More file actions
97 lines (89 loc) · 1.01 KB
/
stack 1.cpp
File metadata and controls
97 lines (89 loc) · 1.01 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#include<iostream>
using namespace std;
#define Max 10
class stack
{
int top;
int arr[Max];
public:
stack(){
top=-1;
}
bool Isempty()
{
if(top==-1)
return true;
else
return false;
}
bool Isfull()
{
if(top==(Max-1))
{
return true;
}
else
{
return false;
}
}
void push(int x);
void pop();
void peek();
};
void stack::push(int x)
{
if(Isfull())
{
cout << "overflow condition" << endl;
}
else
{
top++;
arr[top]=x;
}
}
void stack::pop()
{
if(Isempty())
{
cout << " underflow condition" << endl;
}
else
{
top--;
}
}
void stack::peek()
{
if(Isempty())
{
cout << " underflow condition" << endl;
}
else
{
cout << arr[top] << endl;
}
}
int main()
{
stack a;
a.push(5);
a.push(6);
a.push(7);
a.pop();
a.peek();
a.push(3);
a.push(4);
a.push(8);
a.push(0);
a.push(5);
a.push(4);
a.push(3);
a.push(2);
a.peek();
a.push(11);
a.pop();
a.peek();
return 0;
}