-
Notifications
You must be signed in to change notification settings - Fork 0
/
stack using class in c++.cpp
75 lines (75 loc) · 1.02 KB
/
stack using class in c++.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
#include<iostream>
#define maxsize 5
void menu();
int top=-1;
int arr[maxsize];
using namespace std;
class stack
{
int item;
public:
void insert()
{
if(top==maxsize-1)
{
printf("\nstack is full");
return;
}
else
{
cout<<"\nenter the number"<<endl;
cin>>item;
top++;
arr[top]=item;
}
}
void del()
{
if(top==-1)
{
cout<<"empty"<<endl;
return;
}
else
cout<<"delete no is="<<arr[top]<<endl;
top--;
}
void disp()
{
if(top==-1)
{
cout<<"empty"<<endl;
return;
}
else
{
for(int i=0;i<=top;i++)
{
cout<<arr[i]<<endl;
}
}
}
};
int main()
{
while(1)
menu();
}
void menu()
{
stack p;
int ch;
cout<<"\n ----------menu -----------\n1.inset\n2.del\n3.show\n4.exit"<<endl;
cout<<"\n choice"<<endl;
cin>>ch;
switch(ch)
{
case 1:p.insert();
break;
case 2:p.del();
break;
case 3:p.disp();
break;
default:cout<<"invalid opt"<<endl;
}
}