-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstackwithcpp.cpp
More file actions
43 lines (40 loc) · 878 Bytes
/
Copy pathstackwithcpp.cpp
File metadata and controls
43 lines (40 loc) · 878 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
//STACK OPERATIONS USING CPP
#include<iostream>
#include<stack>
using namespace std;
int main()
{
int n,num;
stack<int> stack;
cout<<"Welcome to menu driven program on stack\n";
while(1)
{
cout<<"1)Push\n2)Pop\n3)Display\n4)Exit\n";
cout<<"Enter a choice:";
cin>>n;
switch(n)
{
case 1:
cout<<"Enter an element to push:-";
cin>>num;
stack.push(num);
break;
case 2:
stack.pop();
break;
case 3:
for(std::stack<int> dump=stack;!dump.empty();dump.pop())
{
std::cout<<dump.top()<<" ";
}
cout<<endl;
break;
case 4:
exit(0);
break;
default:
cout<<"Enter a valid choice:";
}
}
return 0;
}