edited by
869 views
2 votes
2 votes

Consider implementation of stack using queue by following algorithm.

Let $x$ be an element to be pushed in the stack

push(q1,x)
{
    EQ(q1,x)
    
    while(q1 does not contain 1 element) {
        k=DQ(q1)
        EQ(q1,k)
    }
    
}
pop(q1) {
    DQ(q1)
}

How many enqueue and dequeue operations required to push $2$ and pop $2$ elements in the empty stack?

edited by

2 Answers

0 votes
0 votes
for 2 push-   2 en-queue

for 2 pop-     infinite en-queue and infinite de-queue

Related questions

0 votes
0 votes
1 answer
1
Souvik33 asked Nov 2, 2022
870 views
Which data structure would be most appropriate to implement a collection of values with the following 3 characteristicsSingly link list with head and tail pointerDoubly l...