1,848 views
2 2 votes

Suppose Stack operations are implemented using Queue Operation. Push(x) and Pop() are stack operations whereas enqueue(x) and dequeue are Queue operations.
Consider the code:

pop()
{
    return Q.dequeue();    
}
push(x)
{
    n= Q.size();    //Q.size() returns the number of elements in the Queue Q.
    Q.enqueue(x);
    for(i=0;i<n;i++)
    {
        X STATEMENT
    }
}

Find the missing statement X STATEMENT to perform Push() operation correctly

(A) Q.enqueue(x)
(B) Q.enqueue(Q.deqeue())
(C) Q.dequeue(Q.enqueue(x))
(D) Q.dequeue()

1 Answer

Position:
Show:

Related questions

7 7 votes
1 1 answer
451
451 views
GO Classes asked Jul 27
451 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...
6 6 votes
2 2 answers
6.7k
6.7k views
SSrawat asked Oct 9, 2017
6,712 views
A queue is implemented using 2 stacks. Minimum no. of stack operations (PUSH and POP) required for the sequence of 3 insertions and 2 delete operations in the queue is ...
2 2 votes
2 2 answers
2.4k
2.4k views
Gurdeep Saini asked Jan 2, 2019
2,372 views
true/false ?) if stack is implemented as a array,all operation push ,pop ,is emptystack(),delete stack() can be performed in constant time.)if stack is implemented as a l...
0 0 votes
0 0 answers
982
982 views
srestha asked Dec 22, 2018
982 views
Is priority queue work efficiently with sorted array than unsorted array and heap for insertion and deletion operation? Then why do we apply priority queue in heap specia...