-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathqueue_implement.c
More file actions
75 lines (68 loc) · 1.53 KB
/
Copy pathqueue_implement.c
File metadata and controls
75 lines (68 loc) · 1.53 KB
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<stdio.h>
#include<stdlib.h>
#define SIZE 10
int front=0,rear=-1;
int *arr=NULL;
int main()
{
arr=(int *)malloc(sizeof(int)*SIZE);
while(1)
{
printf("Press 1 to enqueue.\nPress 2 to dequeue.\nPress 3 to view front.\nPress 4 to show all elements of queue.\nPress any other key to exit.\n");
int choice;
scanf("%d",&choice);
if(choice==1)
{
//insert
int data;
scanf("%d",&data);
if(rear+1<SIZE)
{
arr[++rear]=data;
}
else
{
printf("QUEUE ALREADY FULL\n");
}
}
else if(choice==2)
{
if(front+1<=rear)
{
front++;
if(front==rear)
{
//resetting the pointers so that it is reusable
front=0;
rear=-1;
}
}
else
{
printf("QUEUE EMPTY\n");
}
}
else if(choice==3)
{
if(rear!=-1)
{
printf("FRONT ELEMENT : %d\n",arr[front]);
}
else
{
printf("QUEUE EMPTY\n");
}
}
else if(choice==4)
{
while(front<=rear)
{
printf("%d , ",arr[front]);
front++;
}
printf("\n");
}
else
break;
}
}