1,233 views
2 votes
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

0 votes
0 votes
First run the push code and enter atleast 2 elements,then perform pop operation

Related questions

6 votes
6 votes
2 answers
1
SSrawat asked Oct 9, 2017
6,024 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 votes
2 votes
2 answers
2
0 votes
0 votes
0 answers
3
srestha asked Dec 22, 2018
603 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...