Bird
0
0
DSA Cprogramming~10 mins

Double Ended Queue Deque in DSA C - Interactive Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to initialize the front index of the deque to -1.

DSA C
int front = [1];
Drag options to blanks, or click blank then click option'
A-1
B0
C1
DNULL
Attempts:
3 left
💡 Hint
Common Mistakes
Initializing front to 0 causes confusion with valid index.
2fill in blank
medium

Complete the code to check if the deque is full when using a circular array of size MAX.

DSA C
if ((front == 0 && rear == MAX - 1) || (front == rear + 1)) {
    // Deque is full
    [1];
}
Drag options to blanks, or click blank then click option'
Aexit(1)
Breturn 0
Cprintf("Full")
Dreturn 1
Attempts:
3 left
💡 Hint
Common Mistakes
Returning 0 instead of 1 for full condition.
3fill in blank
hard

Fix the error in the code that inserts an element at the front of the deque.

DSA C
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;
}
Drag options to blanks, or click blank then click option'
A1
B0
CMAX - 1
D*front - 1
Attempts:
3 left
💡 Hint
Common Mistakes
Setting front to 0 causes overwrite of first element.
4fill in blank
hard

Fill both blanks to correctly delete an element from the rear of the deque.

DSA C
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)--;
    }
}
Drag options to blanks, or click blank then click option'
A-1
B0
C1
DMAX - 1
Attempts:
3 left
💡 Hint
Common Mistakes
Setting front or rear to 0 instead of -1 after last deletion.
5fill in blank
hard

Fill all three blanks to correctly insert an element at the rear of the deque.

DSA C
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;
}
Drag options to blanks, or click blank then click option'
A0
B-1
DMAX - 1
Attempts:
3 left
💡 Hint
Common Mistakes
Incorrectly initializing front or rear to -1 when inserting first element.