1,437 views
1 1 vote
A queue is implemented using two stack A and B. Consider the following code void enqueue(int value)

{

While (!B.is Empty())

A.push(B.Pop());

A. push (value);

}

int dequeue ()

{

While (!A.is Empty())

{X}

return B.Pop();

}

if enqueue is implemented using two stacks A & B With operation Push ,Pop and is empty of stacks then find the missing statement X to implement dequeue operation of the queue .

A)

A.Push(B.Pop());

B)

B.Push(A.Pop());

C)

A.Pop(B. Push ());

D)

B.Pop(A. Push ());

what is difference between option b,d???

Please log in or register to answer this question.

Position:
Show:

Related questions

9 9 votes
2 2 answers
467
467 views
GO Classes asked Jul 27
467 views
Given a stack $S$ with $5$ elements from top to bottom as:$2, 4, 6, 8, 10$and an empty queue $Q$.First, remove the elements one by one from $S$ and insert them into $Q$.T...
8 8 votes
2 2 answers
573
573 views
GO Classes asked Jul 27
573 views
Which of the following statements are true?$\text{S1.}$ Stack operations $\texttt{push}$, $\texttt{pop}$, and $\texttt{isEmpty}$ can be worst-case $O(1)$ for a linked-lis...
4 4 votes
1 1 answer
214
214 views
GO Classes asked Jul 10
214 views
Suppose a client performs an intermixed sequence of $\texttt{enqueue}$ and $\texttt{dequeue}$ operations on a queue. The enqueue operations put the integers $0$ through $...
8 8 votes
3 3 answers
344
344 views
GO Classes asked Jul 8
344 views
A queue is implemented using two stacks $\text{S1}$ and $\text{S2}$.Use the implementation where $\texttt{dequeue()}$ is $\text{O(1)}$ by keeping the front of the queue a...