-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue using stackes.cpp
More file actions
115 lines (114 loc) · 1.52 KB
/
queue using stackes.cpp
File metadata and controls
115 lines (114 loc) · 1.52 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include<iostream>
using namespace std;
int s1[5],s2[5],top1=-1,top2=-1;
void create();
void traverse();
void insert();
void del();
void create()
{
int n;
cout<<"\n enter the number of elements you wannt to insert : ";
cin>>n;
if(n>5)
{
cout<<"\noverflow ";
exit(0);
}
else
{
for(int j=0;j<n;j++)
{
top1+=1;
cout<<"\n enter the "<<j<< " element : ";
cin>>s1[j];
}
}
}
void traverse()
{
if(top1==-1)
{
cout<<"\n underflow ";
exit(0);
}
else
{
for(int j=0;j<=top1;j++)
{
cout<<"\n"<<s1[j];
}
}
}
void insert ()
{
if(top1==4)
{
cout<<"\n overflow ";
exit(0);
}
else
{
int x;
cout<<"\n enter the element : ";
cin>>x;
top1+=1;
s1[top1]=x;
}
}
void del()
{
if(top1==-1)
{
cout<<"\nlist is empty ,underflow ";
exit(0);
}
else
{
while(top1!=-1)
{
top2+=1;
s2[top2]=s1[top1];
top1-=1;
}
int item;
item=s2[top2];
top2=top2-1;
while(top2!=-1)
{
top1+=1;
s1[top1]=s2[top2];
top2-=1;
}
cout<<"\n the elements deleted is : "<<item;
}
}
int main()
{
int n,q=0;
do
{
cout<<"\n1.create \n 2.insert \n 3.delete \n 4.traverse \n : ";
cin>>n;
switch(n)
{
case 1:
create();
traverse();
break;
case 2:
insert();
traverse();
break;
case 3:
del();
traverse();
break;
default :
traverse();
break;
}
cout<<"\nenter 1 to exit else any button to continue : ";
cin>>q;
}while(q!=1);
}