-
Notifications
You must be signed in to change notification settings - Fork 116
/
queue.cpp
75 lines (75 loc) · 1.09 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
#include"conio.h"
#include"stdio.h"
#include"process.h"
void enquee(int);
void dequee();
void display();
int FRONT=-1,REAR=-1,SIZE[10];
void main()
{
clrscr();
int choice,num;
while(1)
{
printf("\n1.insertion in quee\n");
printf("2.deletion in quee\n");
printf("3.display of list elements\n");
printf("4.exit\n");
printf("\tenter your choice");
scanf("%d",&choice);
switch(choice)
{
case 1:printf("enter a element to insert: ");
scanf("%d",&num);
enquee(num);
break;
case 2: dequee();
break;
case 3: display();
break;
case 4: exit(0);
break;
}
}
}
void enquee(int n)
{
if(FRONT==-1)
{
FRONT=0;
REAR=0;
SIZE[REAR]=n;
}
else
if(REAR==9)
printf("list is full\n");
else
{
if(FRONT==-1)
{FRONT=0;}
REAR++;
SIZE[REAR]=n;
}
}
void dequee()
{
if(FRONT==-1)
printf("list is empty\n");
else
if(FRONT==REAR)
FRONT=REAR=-1;
else
FRONT++;
}
void display()
{
int f=FRONT,r=REAR;
if(f==-1)
printf("list is empty\n");
else
do
{
printf("%d\t",SIZE[f]);
f++;
} while(f!=r+1);
}