forked from namishkhanna/hacktoberfest2020
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasic_queue_operations.c
More file actions
78 lines (67 loc) · 1.2 KB
/
Copy pathBasic_queue_operations.c
File metadata and controls
78 lines (67 loc) · 1.2 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
76
#include <stdio.h>
#define max 5
int queue[max];
int front=-1,rear=-1;
void enqueue(){
int data;
printf ("Enter the element to be added\n");
scanf ("%d", &data);
if(rear==max-1){
printf("Overflow");
}else if(rear==-1 && front==-1){
rear=front=0;
queue[rear]=data;
}else{
rear++;
queue[rear]=data;
}
}
int dequeue(){
if((front==-1 && rear ==-1 )|| front> rear){
printf("underflow");
}else{
return queue[front++];
}
}
void display(){
if((front==-1 && rear ==-1 )|| front> rear){
printf("underflow");
}else{
int i;
printf("\n");
for(i=front;i<=rear;i++){
printf("%d ",queue[i]);
}
}
}
int main ()
{
int choice;
int option = 1;
printf ("QUEUE OPERATION\n");
while (option)
{
printf ("------------------------------------------\n");
printf (" 1 --> ENQUEUE \n");
printf (" 2 --> DEQUEUE \n");
printf (" 3 --> DISPLAY \n");
printf (" 4 --> EXIT \n");
printf ("------------------------------------------\n");
printf ("Enter your choice\n");
scanf ("%d", &choice);
switch (choice)
{
case 1: enqueue();
break;
case 2: dequeue();
break;
case 3: display();
break;
case 4: return;
}
fflush (stdin);
printf ("Do you want to continue(Type 0 or 1)?\n");
scanf ("%d", &option);
}
return 0;
}