-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5.1.cpp
65 lines (65 loc) · 1.25 KB
/
5.1.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
#include<iostream>
using namespace std;
void push(int);
void pop();
void peak();
void display();
int stack[1000],s,top=-1;
int main()
{
int c,i;
cout<<"enter the size of the stack"<<endl;
cin>>s;
while(1)
{
cout<<"1.push\n2.pop\n3.peak\n4.display\n5.exit"<<endl;
cout<<"enter your choice"<<endl;
cin>>c;
if(c==5)
break;
switch (c)
{
case 1: push(s);
break;
case 2: pop();
break;
case 3: peak();
break;
case 4: display();
break;
default:cout<<"enter correct choice"<<endl;
break;
}
}
return 0;
}
void push(int s)
{
int n;
if(top<s-1)
{
cout<<"enter the element"<<endl;
cin>>n;
stack[++top] = n;
}
else
cout<<"stack is full no further element can be taken to perform push operation"<<endl;
}
void pop()
{
if(top>=0)
top--;
else
cout<<"stack is completely empty no further element is present to perform pop operation"<<endl;
}
void peak()
{
cout<<"Top element of the stack is "<<stack[top]<<endl;
}
void display()
{
cout<<"stack elements are"<<endl;
for(int i=0;i<top+1;i++)
cout<<stack[i]<<" ";
cout<<endl;
}