-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy path_6.b.QueueUsingArrays.c
81 lines (80 loc) · 1.75 KB
/
_6.b.QueueUsingArrays.c
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
#include<stdio.h>
void enqueue(int* front, int* rear, int size, int* arr)
{
int element, begin, end;
if(*rear==size-1)
{
printf("\nQUEUE FULL!\n");
}
else
{
printf("Enter the element to be inserted:");
scanf("%d",&element);
if(*rear==-1 && *front==-1)
{
*front=*front+1;
}
*rear=*rear+1;
*(arr+*rear)=element;
}
}
void dequeue(int* front, int* rear, int size, int* arr)
{
if((*front==-1 && *rear==-1) || *front>*rear)
{
printf("\nQUEUE EMPTY!\n");
}
else
{
*front=*front+1;
}
}
void view(int* front, int* rear, int size, int* arr)
{
int begin, end;
begin=*front;
end=*rear;
if((*front==-1 && *rear==-1) || *front>*rear)
{
printf("\nQUEUE EMPTY!\n");
}
else
{
while (begin<=end)
{
printf("%d\t",*(arr+begin));
begin++;
}
printf("\n");
}
}
int main()
{
printf("\n*****IMPLEMENTATION OF QUEUE USING ARRAYS*****\n");
int n, option, front=-1, rear=-1, flag=0;
printf("Enter the size of the queue:");
scanf("%d",&n);
int arr[n];
while(flag==0)
{
printf("-----------------------------------------------------------");
printf("\nChoose an option:\n1.Enqueue\t2.Dequeue\t3.Display.\t4.Exit\nCHOICE :");
scanf("%d",&option);
//printf("rear=%d\n",rear);
switch (option)
{
case 1:
enqueue(&front, &rear, n, arr);
break;
case 2:
dequeue(&front, &rear, n, arr);
break;
case 3:
view(&front, &rear, n, arr);
break;
case 4:
flag=1;
break;
}
}
}