Stack & Queues using C

Last Updated :
Discuss
Comments

Question 1

Which of the following best prevents overflow in a circular queue implementation?


  •  rear == MAX - 1


  • rear == front


  • (rear + 1) % MAX == front


  • rear > front

Question 2

What is the main drawback of a stack implemented using a fixed-size array compared to a linked list stack?


  • Access time is slower

  •  Can’t support push/pop operations

  • Stack has dynamic size

  • Memory is limited and can't grow beyond a fixed size

Question 3

In a queue implemented using an array, what typically causes wasted space at the front of the array after multiple dequeues?


  • Queue elements are not initialized


  •  Only rear is updated on enqueue, front stays at 0


  •  Front pointer moves forward, but array indices are not reused


  • Elements are deleted from the middle


Question 4

You have the following circular queue:

C
#define MAX 4
int queue[MAX];
int front = 0, rear = 0;

If you perform the following operations:

enqueue(1); enqueue(2); enqueue(3); dequeue(); enqueue(4);

Which element will be at queue[rear]?

  • 1

  • 4

  • 3

  • 2

Question 5

Which of the following input sequences can’t be the result of a stack performing push and pop operations on input: 1 2 3 4 5?


  • 5 4 3 2 1

  • 1 2 3 4 5

  • 3 2 1 5 4

  • 3 5 4 1 2

There are 5 questions to complete.

Take a part in the ongoing discussion