Bird
0
0
DSA Cprogramming~10 mins

Peek Front Element of Queue 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 return the front element of the queue.

DSA C
int peekFront(struct Queue* q) {
    if (q->front == -1) {
        return -1; // Queue is empty
    }
    return q->array[q->[1]];
}
Drag options to blanks, or click blank then click option'
Acapacity
Brear
Csize
Dfront
Attempts:
3 left
💡 Hint
Common Mistakes
Using q->array[q->rear] instead of q->array[q->front]
Returning q->size or q->capacity instead of an element
Not checking if the queue is empty before accessing
2fill in blank
medium

Complete the code to check if the queue is empty before peeking.

DSA C
int peekFront(struct Queue* q) {
    if (q->[1] == -1) {
        return -1; // Queue is empty
    }
    return q->array[q->front];
}
Drag options to blanks, or click blank then click option'
Arear
Bsize
Cfront
Dcapacity
Attempts:
3 left
💡 Hint
Common Mistakes
Checking rear instead of front for emptiness
Checking size or capacity which may not reflect emptiness
Not returning -1 when queue is empty
3fill in blank
hard

Fix the error in the peek function to correctly handle empty queue.

DSA C
int peekFront(struct Queue* q) {
    if ([1]) {
        return -1; // Queue is empty
    }
    return q->array[q->front];
}
Drag options to blanks, or click blank then click option'
Aq->rear == -1
Bq->front == -1
Cq->front == q->rear
Dq->size == 0
Attempts:
3 left
💡 Hint
Common Mistakes
Checking front == 0 instead of front == -1
Using rear or size incorrectly to check emptiness
4fill in blank
hard

Fill both blanks to correctly implement peekFront with empty check and return front element.

DSA C
int peekFront(struct Queue* q) {
    if (q->[1] == -1) {
        return -1; // Queue is empty
    }
    return q->array[q->[2]];
}
Drag options to blanks, or click blank then click option'
Afront
Brear
Dsize
Attempts:
3 left
💡 Hint
Common Mistakes
Using rear instead of front for empty check
Returning element at rear instead of front
5fill in blank
hard

Fill all three blanks to implement peekFront with empty check, return front element, and print error if empty.

DSA C
int peekFront(struct Queue* q) {
    if (q->[1] == -1) {
        printf("[2]\n");
        return [3];
    }
    return q->array[q->front];
}
Drag options to blanks, or click blank then click option'
Afront
BQueue is empty
C-1
Drear
Attempts:
3 left
💡 Hint
Common Mistakes
Not printing error message when queue is empty
Returning wrong error code
Checking wrong index for emptiness