forked from AugustineAykara/Data-Structure-In-C
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqueue-array.c
More file actions
96 lines (82 loc) · 1.28 KB
/
queue-array.c
File metadata and controls
96 lines (82 loc) · 1.28 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include<stdio.h>
#include<stdlib.h>
int size, item, queue[10], front = -1, rear = -1;
void insertQueue()
{
int item;
if (rear == size - 1)
{
printf("\n QUEUE OVERFLOW !!!\n");
}
else
{
if (front == -1)
{
front = 0;
}
printf("\n Enter the item to be inserted : ");
scanf("%d", &item);
printf("\n");
rear++;
queue[rear] = item;
}
}
void deleteQueue()
{
if (front == -1 || front > rear)
{
printf("\n QUEUE UNDERFLOW !!!");
}
else
{
printf("\n Element %d deleted from the Queue ", queue[front]);
front++;
if (front > rear)
{
front = rear = -1;
}
}
printf("\n");
}
void display()
{
int i;
if (front == -1)
{
printf("\n List is empty !!!");
}
else
{
for (i = front; i<=rear ; ++i)
{
printf(" %d <- ", queue[i]);
}
}
printf("\n");
}
void main()
{
int ch, item;
printf("\n Enter the size of the array : ");
scanf("%d", &size);
while(1)
{
printf("\n 1.INSERT to Queue \n 2.DELETE from Queue \n 3.DISPLAY \n 4.EXIT");
printf("\n Enter your choice : ");
scanf("%d", &ch);
switch(ch)
{
case 1: insertQueue();
display();
break;
case 2: deleteQueue();
display();
break;
case 3: display();
break;
case 4: exit(0);
break;
default: printf("\n INVALID CHOICE !!!");
}
}
}