-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.cpp
More file actions
98 lines (76 loc) · 995 Bytes
/
stack.cpp
File metadata and controls
98 lines (76 loc) · 995 Bytes
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
#include<iostream>
using namespace std;
#define MAX 100
int i,j,top;
int s[MAX];
class skstack
{
public:
skstack()
{
top= -1;
for(i=0;i<MAX;i++)
{
s[i]=NULL;
}
}
int push(int val);
int pop();
int display();
int isempty();
};
int skstack:: push(int val)
{
if(top>=MAX-1)
{
cout<<"stack is overflow ";
}
else
{
top++;
s[top]=val;
}
}
int skstack :: pop()
{
if(top<= -1)
{
cout<<"stack is underflow "<<endl;
}
else
{
cout<<"pop element "<<s[top]<<endl;
top--;
}
}
int skstack:: isempty()
{
return (top<0);
}
int skstack::display()
{
if(top<=-1)
{
cout<<"stack is empty now "<<endl;
}
else
{
for(i=0;i<=top;i++)
{
cout<<"Current value in stack is : "<<s[i]<<endl;
}
}
}
int main()
{
skstack s;
s.isempty();
s.push(30);
s.push(40);
s.display();
s.pop();
s.display();
s.pop();
s.display();
return 0;
}