-
Notifications
You must be signed in to change notification settings - Fork 1
/
Queue
79 lines (71 loc) · 1.11 KB
/
Queue
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
#include<stdio.h>
#include<conio.h>
void enqueue(int *array,int x,int *rear)
{
*(array+*rear)=x;
*rear=*rear+1;
}
int dequeue(int *array,int *front,int *rear)
{
int x=*(array+*front);
*front=*front+1;
if(*front==*rear)
{*front=-1;*rear=-1;}
return x;
}
void peek(int *array,int *front,int *rear)
{
if(*front!=*rear)
printf("%d",*(array+*front));
}
void display(int *array,int *rear,int *front)
{
int i=*front,j=*rear;
for(;i<j;i++)
printf("%d",*(array+i));
}
void main()
{
int size,*r,*array,ch,l=0,x,*f;
*r=-1;
*f=-1;
clrscr();
printf("Enter the size of array");
scanf("%d",&size);
array=(int*)malloc(2*size);
do
{
printf("Enter 1.Enqueue 2.Dequeue 3.Peek 4.Display :");
scanf("%d",&ch);
switch(ch)
{
case 1:if(*r+1<size)
{
printf("Enter the element to insert : ");
scanf("%d",&x) ;
enqueue(array,x,r);
}
else
{
printf("Queue Full");
}
break;
case 2:if(*r==*f)
printf("Queue Empty");
else
{
x=dequeue(array,f,r);
printf("Element dequeued is %d",x);
}
break;
case 3:peek(array,f,r);
break;
case 4:display(array,r,f);
break;
case 5:l=1;
break;
default:printf("Invalid Choice");
}
}while(l==0);
getch();
}