MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

DATA STRUCTURES

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
Can We Implement Stack Using Queue Data structure
A
Yes
B
No
C
Either A or B
D
None of the above
Explanation: 

Detailed explanation-1: -There are two approaches to implement stack using Queue: First, we can make the push operation costly. Second, we can make the pop operation costly.

Detailed explanation-2: -The last element added at the top of the stack (In) can be the first element to be removed (Out) from the stack. A Queue class extends Collection interface and it supports the insert and removes operations using a first-in-first-out (FIFO). We can also implement a Stack using Queue in the below program.

Detailed explanation-3: -In order to implement the Queue using Stack, we need to consider two stacks. There are two approaches to implement Queue using Stack: Making a dequeue operation costly.

Detailed explanation-4: -Queue is First In First Out data structure. Push and pop operations take place through two ends of the queue. It supports enqueue, dequeue, peek operations. So, if you clearly observe, we would require two stacks to implement the queue, one for en queue and another for de queue operation.

Detailed explanation-5: -This is a C Program to implement stack using queue. The idea is pretty simple. We start with an empty queue. For the push operation we simply insert the value to be pushed into the queue.

There is 1 question to complete.