-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExperiment 5.cpp
More file actions
60 lines (55 loc) · 868 Bytes
/
Copy pathExperiment 5.cpp
File metadata and controls
60 lines (55 loc) · 868 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include<bits/stdc++.h>
using namespace std;
#define MAX 6
int Stack[MAX];
int top = -1;
void push(int x);
void pop();
void display();
int main ()
{
int choice, val;
choice = -1;
while(choice !=4)
{
cin>> choice;
switch(choice)
{
case 1:// cout<<”Enter the element to push”;
cin>>val;
push(val);
break;
case 2: // cout<<”Enter the element to pop”;
pop();
break;
case 3:// cout<<”Display the stack elements”;
display();
break;
default:
break;
}
cout<<"choice please"<<endl;
}
return 0;
}
void push(int x)
{ if(top==MAX)
cout<<"overflow "<<endl;
else
{
Stack[top+1]=x;
top++;
}
}
void pop()
{ if(top==-1)
cout<<"underflow sir!"<<endl;
else
{cout<<"deleted element is"<<" "<<Stack[top--]<<endl;
}
}
void display()
{for(int i=top;i>-1;i--)
cout<<Stack[i]<<" ";
cout<<endl;
}