-
Notifications
You must be signed in to change notification settings - Fork 2
/
QUEUE.cpp
105 lines (105 loc) · 1.33 KB
/
QUEUE.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
//Queue Operation
#include<iostream.h>
#include<conio.h>
class Queue
{
int QueueData[100], size, front, rear;
public:
Queue()
{
front=0;
rear=0;
}
void SetSize(int n)
{
size=n;
}
void Enque(int);
int Deque(void);
void View(void);
};
void Queue::Enque(int x)
{
if((rear-front+1)>size)
{
cout<<"\n\t\tQueue is over flow...";
}
else
{
QueueData[rear]=x;
cout<<"\n\t\t"<<x<<" is added.\n";
rear++;
}
}
int Queue::Deque(void)
{
int x;
if(front>=rear)
{
cout<<"\n\t\tQueue is under flow...";
return -9999;
}
else
{
x=QueueData[front];
front++;
return x;
}
}
void Queue::View()
{
int i=front, j=rear;
if(i>=j)
{
cout<<"\n\t\tQueue is empty...";
}
else
{
cout<<"\n\n\tData in Queue :";
for(i;i<=j-1;i++)
cout<<" "<<QueueData[i];
}
}
int main()
{
clrscr();
int n;
cout<<"\n Enter the size of Queue [MAX=100] : ";
cin>>n;
Queue Q;
Q.SetSize(n);
int choice;
do
{
clrscr();
cout<<"\n\t\t Queue Operation";
cout<<"\n\t\t***************";
cout<<"\n\n\t 1.INSERT\n\t 2.DELETE\n\t 3.VIEW\n\t 4.EXIT";
cout<<"\n\n Enter your choice : ";
cin>>choice;
int x;
switch(choice)
{
case 1:
cout<<"\n Enter a value : ";
cin>>x;
Q.Enque(x);
Q.View();
break;
case 2:
x=Q.Deque();
if (x!=-9999)
cout<<"\n\n\t"<<x<<" is deleted.\n\n";
Q.View();
break;
case 3:
Q.View();
break;
case 4:
cout<<"\n\n\t\t Exit...";
break;
}
getch();
}while(choice!=4);
return 0;
}