-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2021831024_stack_push_pop.cpp
More file actions
46 lines (43 loc) · 1.15 KB
/
2021831024_stack_push_pop.cpp
File metadata and controls
46 lines (43 loc) · 1.15 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
#include<iostream>
using namespace std;
void push(int a[], int &size, int &top, int item){
if (top == size - 1){
cout << "stack overflow !!! \n";
return;
}
top++;
a[top] = item;
}
void pop (int a[], int &topp,int &size){
if (topp == -1){
cout << "stack underflow !!! \n";
return;
}
topp--;
}
int main() {
cout << "enter max size of stack : ";
int maxsize; cin >> maxsize;
int stack[maxsize];
int top = -1;
int option;
int ele;
do {
cout << "Menu\n";
cout << "1. Push \n2. Pop \n3. Display \n4. Exit \n";
cout << "enter option : "; cin >> option;
switch(option){
case 1:
cout << "enter element to insert : "; cin >> ele;
push(stack, maxsize, top, ele);break;
case 2:
pop(stack, top, maxsize);break;
case 3:
cout << "current stack elements : ";
for (int i = 0; i <= top; i++){
cout << stack[i] << ' ';
}
cout << '\n';break;
}
}while (option < 4);
}