-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack_using_vector.cpp
73 lines (66 loc) · 1.04 KB
/
stack_using_vector.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
72
73
#include<bits/stdc++.h>
using namespace std;
int main(){
// stack using array
vector<int> a;
int top=-1;
int i=0;
while(i!=6){
cout<<"choose option \n";
cout<<"Enter 1 for push \n";
cout<<"Enter 2 for pop \n";
cout<<"Enter 3 for top \n";
cout<<"Enter 4 for print \n";
cout<<"Enter 5 for size \n";
cout<<"Enter 6 to exit \n";
cin>>i;
if(i==1){
cout<<"Enter element"<<endl;
int n;
cin>>n;
a.push_back(n);
top++;
}
else if(i==2){
if(top>-1){
cout<<"popped succesfully \n";
top--;
}
else{
cout<<"stack is empty \n";
}
}
else if(i==3){
if(top>-1){
cout<<"top element is"<<a[top]<<"\n";
}
else{
cout<<"stack is empty \n";
}
}
else if(i==4){
if(top>-1){
for (int j=0;j<=top;j++){
cout<<a[j]<<endl;
}
}
else{
cout<<"stack is empty \n";
}
}
else if(i==5){
if(top>-1){
cout<<"size of stack is: "<<top<<"\n";
}
else{
cout<<"stack is empty \n";
}
}
else if(i==6){
cout<<"Thanks for using \n";
}
else{
cout<<"please try again \n";
}
}
}