-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqueue using array.cpp
68 lines (66 loc) · 1.84 KB
/
queue using array.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
#include<iostream>
#include<conio.h>
#include<stdlib.h>
using namespace std;
class queue
{
int queue1[5];
int rear,front;
public:
queue()
{
rear=-1;
front=-1;
}
void insert(int x)
{
if(rear > 4)
{
cout <<"queue over flow";
front=rear=-1;
return;
}
queue1[++rear]=x;
cout <<"\nInserted: " <<x;
}
void del()
{
if(front==rear)
{
cout <<"queue under flow";
return;
}
cout <<"\nDeleted: " <<queue1[++front];
}
void display()
{
if(rear==front)
{
cout <<" queue empty";
return;
}
for(int i=front+1;i<=rear;i++)
cout <<queue1[i]<<"\n";
}
};
main()
{
int ch;
queue ob;
while(1)
{
cout <<"\n1.Insert \n2.Delete \n3.Display \n4.Exit\n\nEnter ur choice: ";
cin >> ch;
switch(ch)
{
case 1: cout <<"\nEnter the element: ";
cin >> ch;
ob.insert(ch);
break;
case 2: ob.del(); break;
case 3: ob.display();break;
case 4: exit(0);
}
}
return (0);
}