-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStaticStack.cpp
71 lines (69 loc) · 1.32 KB
/
StaticStack.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
71
#include<iostream>
using namespace std;
int top;
void push(int stack[],int num)
{
if(top==49)
cout<<"stack is full";
else
{
top++;
stack[top]=num;
}
}
void pop(int stack[])
{
if(top==-1)
cout<<"stack is empty";
else
{
cout<<"popped value:"<<stack[top];
top--;
}
}
void display(int stack[])
{
if(top==-1)
cout<<"stack is empty";
else
{
cout<<"elements are:"<<endl;
for(int i=top;i>0;i--)
cout<<stack[i]<<endl;
}
}
int main()
{
int stack[50];
int num,choice;
int top=-1;
while(true)
{
cout<<"\n*************** MENU *******************"<<endl;
cout<<"1.push"<<endl;
cout<<"2.pop"<<endl;
cout<<"3.display"<<endl;
cout<<"4.exit"<<endl;
cout<<"enter your choice : "<<endl;
cin>>choice;
switch(choice)
{
case 1:
cout<<"enter number to push : ";
cin>>num;
push(stack,num);
break;
case 2:
pop(stack);
break;
case 3:
display(stack);
break;
case 4:
exit(0);
default:
cout<<"invalid inupt";
}
}
return 0;
}