-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack.cpp
83 lines (78 loc) · 1.62 KB
/
stack.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
74
75
76
77
78
79
80
81
82
83
#include<iostream>
using namespace std;
# define size 10
class stack
{
int num[size];
int top;
public:
stack(){top=-1;}
void push()
{
int item;
cout<<"enter item to be inserted ";
cin>>item;
if(top==10)
{
cout<<"stack is full ";
}
else
{
num[++top]=item;
}
}
void pop()
{ int del;
if (top==0)
{
cout<<"stack is empty ";
}
else
{
del=num[top];
top--;
}
}
void status()
{ int space;
if(top>10)
cout<<"stack is full ";
else if(top<-1)
cout<<"stack is empty ";
else
space=size-top;
cout<<"free space is "<<space;
}
void display()
{
if(top==0)
cout<<"empty stack";
else
cout<<"stack is";
for(int i=0;i<=top;i++)
{
cout<<" \n"<<num[i] ;
}
}
};
int main()
{ int d;
stack a1;
do{ cout<<" enter 1.push\n 2.pop\n 3.status \n4.display\n 5.exit\n ";
cin>>d;
switch(d)
{
case 1: a1.push();
break;
case 2: a1.pop();
break;
case 3: a1.status();
break;
case 4: a1.display();
break;
case 5: break;
default: cout<<"invalid\n";
}
} while(d!=5);
return 0;
}