forked from rituburman/hacktoberfest2020
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray stack
More file actions
77 lines (76 loc) · 980 Bytes
/
array stack
File metadata and controls
77 lines (76 loc) · 980 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
#include<iostream>
using namespace std;
#define N 5
int stack[N];
int top=-1;
void push()
{
int x;
cout<<" enter tha element"<<endl;
cin>>x;
if(top==N-1)
cout<<"overflow\n";
else
{
top++;
stack[top]=x;
}
}
void pop()
{
int item;
if(top==-1)
cout<<"Underflow"<<endl;
else
{
item=stack[top];
top--;
cout<<"pop item="<<item<<endl;
}
}
void peek()
{
if(top==-1)
cout<<"Underflow"<<endl;
else
{
cout<<"top element="<<stack[top]<<endl;
}
}
void dis()
{
int i;
for(int i=top;i>=0;i--)
cout<<stack[i]<<" ";
cout<<endl;
}
int main()
{
int ch;
while(1)
{
cout<<"1 enter tha push element\n\n";
cout<<"2 enter tha pop element\n\n ";
cout<<"3 enter tha peek element\n\n";
cout<<"4 enter tha disply element\n\n";
cin>>ch;
switch(ch)
{
case 1:push();
break;
case 2:
pop();
break;
case 3:
peek();
break;
case 4:
dis();
break;
case 5:
exit(0);
default:
cout<<"invalid item\n\n";
}
}
}