-
Notifications
You must be signed in to change notification settings - Fork 0
/
stacks.cpp
54 lines (54 loc) · 1.17 KB
/
stacks.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
#include<iostream>
using namespace std;
#define SIZE 10
void push(int);
void pop();
void Display();
int stack[SIZE],top=-1;
int main(){
int value,choice;
while(1){
cout<<"MENU:- \n 1.Push \n 2.Pop \n 3.Display \n 5.Exit "<<endl;
cin>>choice;
switch(choice){
case 1: cout<<"Enter the Value to be insert "<<endl;
cin>>value;
push(value);
break;
case 2: pop();
break;
case 3: Display();
break;
case 4: exit(0);
default:
cout<<"Wrong Option"<<endl;
}
}
}
void push(int value){
if(top== SIZE-1)
cout<<"Stack is FULL"<<endl;
else{
top ++;
stack[top]=value;
cout<<"Sucessfully Inserted"<<endl;
}
}
void pop(){
if(top==-1)
cout<<"Stack is EMPTY"<<endl;
else{
cout<<"Deleted: ",stack[top];
top--;
}
}
void Display(){
if(top==-1)
cout<<"Stack is EMPTY"<<endl;
else{
int i;
cout<<"stack element are:-"<<endl;
for(i=top;i>0;i--)
cout<<stack[i]<<endl;
}
}