-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue using array.cpp
More file actions
90 lines (89 loc) · 1.13 KB
/
queue using array.cpp
File metadata and controls
90 lines (89 loc) · 1.13 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
#include<iostream>
using namespace std ;
int a[20],f=-1,r;
void pop();
void push();
void traverse();
void traverse()
{
if(f==-1)
{
cout<<"\n list is empty underflow ";
exit(0);
}
else
{
for(int j=f;j<=r;j++)
{
cout<<a[j]<<endl;
}
}
}
void pop()
{
if(f==-1)
{
cout<<"\n queue is empty ";
exit(0);
}
else
{ int item;
item=a[f];
f+=1;
}
}
void push()
{
int x;
cout<<"\nenter the element : ";
cin>>x;
if(r>=20)
{
cout<<"\n overflow ";
}
else if (f==-1)
{
f+=1;
r=r+1;
a[r]=x;
}
else
{
r=r+1;
a[r]=x;
}
}
int main()
{
int n;
cout<<"\n enter the number of elements you want to add to queue : ";
cin>>n;
f+=1;
r=n-1;
if(n>20)
{
cout<<"\n overflow ";
}
cout<<"\n enter the elements " ;
for(int i=0;i<n;i++)
{
cin>>a[i];
}
int m;
cout<<"\n enter 1 for push and 2 for pop or 3 for traverse : ";
cin>>m;
switch (m)
{
case 1:
push();
traverse();
break;
case 2 :
pop();
traverse();
break;
case 3:
traverse();
break;
}
}