Complete the code to initialize the front index of the deque to -1.
int front = [1];In deque implementation, front is initialized to -1 to indicate the deque is empty.
Complete the code to check if the deque is full when using a circular array of size MAX.
if ((front == 0 && rear == MAX - 1) || (front == rear + 1)) { // Deque is full [1]; }
Return 1 to indicate the deque is full in the isFull function.
Fix the error in the code that inserts an element at the front of the deque.
void insertFront(int deque[], int *front, int *rear, int value) {
if (isFull(*front, *rear)) {
printf("Deque is full\n");
return;
}
if (*front == -1) {
*front = 0;
*rear = 0;
} else if (*front == 0) {
*front = [1];
} else {
(*front)--;
}
deque[*front] = value;
}When front is at 0, moving it to MAX - 1 wraps around the circular array.
Fill both blanks to correctly delete an element from the rear of the deque.
void deleteRear(int deque[], int *front, int *rear) {
if (*front == -1) {
printf("Deque is empty\n");
return;
}
if (*front == *rear) {
*front = [1];
*rear = [2];
} else if (*rear == 0) {
*rear = MAX - 1;
} else {
(*rear)--;
}
}When the last element is deleted, both front and rear are reset to -1 to indicate empty deque.
Fill all three blanks to correctly insert an element at the rear of the deque.
void insertRear(int deque[], int *front, int *rear, int value) {
if (isFull(*front, *rear)) {
printf("Deque is full\n");
return;
}
if (*front == -1) {
*front = [1];
*rear = [2];
} else if (*rear == MAX - 1) {
*rear = [3];
} else {
(*rear)++;
}
deque[*rear] = value;
}When deque is empty, front and rear start at 0. If rear reaches MAX - 1, it wraps to 0.
