forked from AugustineAykara/Data-Structure-In-C
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoublyEndedQueue-array.c
More file actions
138 lines (119 loc) · 1.91 KB
/
doublyEndedQueue-array.c
File metadata and controls
138 lines (119 loc) · 1.91 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include<stdio.h>
#include<stdlib.h>
int size, front = -1, rear = -1, dequeue[10], item;
void insertQueueRear()
{
if (rear == size-1)
{
printf("\n QUEUE OVERRFLOW !!!");
}
else
{
if (front == -1)
{
front = 0;
}
printf("\n Enter the element to be inserted : ");
scanf("%d", &item);
rear++;
dequeue[rear] = item;
}
}
void insertQueueFront()
{
if (front == 0)
{
printf("\n QUEUE OVERFLOW !!!");
}
else
{
if (front == -1)
{
front = rear = 0;
}
else
{
front = front -1;
}
printf("\n Enter the element to be inserted : ");
scanf("%d", &item);
dequeue[front] = item;
}
}
void deleteQueueRear()
{
if (rear == -1)
{
printf("\n QUEUE UNDERFLOW !!!");
}
else
{
printf("\n Element %d has been deleted from the rear", dequeue[rear]);
rear--;
}
}
void deleteQueueFront()
{
if (front == -1 || front > rear)
{
printf("\n QUEUE UNDERFLOW !!!");
}
else
{
printf("\n Element %d has been deleted from the front", dequeue[front]);
front++;
if (front > rear)
{
front = rear = -1;
}
}
}
void display()
{
int i;
if (front == -1)
{
printf("\n List is empty !!!");
}
else
{
printf("\n");
for (i = front; i <= rear; ++i)
{
printf(" %d <-", dequeue[i]);
}
}
printf("\n");
}
void main()
{
int ch, item;
printf("\n Enter the size of the array : ");
scanf("%d", &size);
while(1)
{
printf("\n 1.INSERTION AT FRONT \n 2.INSERTION AT REAR \n 3.DELETION FROM FRONT \n 4.DELTION FROM REAR \n 5.DISPLAY \n 6.EXIT");
printf("\n Enter your choice : ");
scanf("%d", &ch);
switch(ch)
{
case 1: insertQueueFront();
display();
break;
case 2: insertQueueRear();
display();
break;
case 3: deleteQueueFront();
display();
break;
case 4: deleteQueueRear();
display();
break;
case 5: display();
break;
case 6: exit(0);
break;
default: printf("\n INVALID CHOICE !!!");
}
}
}