-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSTACK2.CPP
More file actions
72 lines (65 loc) · 1.06 KB
/
Copy pathSTACK2.CPP
File metadata and controls
72 lines (65 loc) · 1.06 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
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
float stack[40];
int top=0;
float e;
void push()
{
if(top==39)
{
cout<<"Stack overflow"<<endl<<"Delete some elements"<<endl;
return ;
}
cout<<"Enter element(Maximum number of elements is 40)"<<endl;
cin>>e;
stack[top]=e;
top++;
}
void pop()
{
if(top<=0)
{
cout<<"Stack underflow"<<endl<<"Add some elements"<<endl;
return ;
}
top--;
}
void display()
{
if(top<=0)
{
cout<<"Stack underflow"<<endl<<"Add some elements"<<endl;
return ;
}
for(int i=top-1;i>=0;i--)
cout<<stack[i]<<" ";
cout<<endl;
}
int main()
{
int choice;
char ans;
do
{
cout<<"1.Push"<<endl;
cout<<"2.Pop"<<endl;
cout<<"3.Display"<<endl;
cout<<"4.Exit"<<endl;
cin>>choice;
if(choice==4)
exit(0);
else if(choice==1)
push();
else if(choice==2)
pop();
else if(choice==3)
display();
else
cout<<"Enter valid choice"<<endl;
cout<<"Continue?"<<endl;
cin>>ans;
}while(ans=='y');
return 0;
}