Consider implementation of stack using queue by following algorithm. Let x be…
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)
size = q1.size();
while (size > 1) {
k= DQ(q1)
EQ(q1,k)
Size--;
}
}
pop(q1) {
DQ(q1)
}
How many enqueue and dequeue operations required to perform 3 push and 1 pop sequentially in an empty stack?
- A.
6EQ, 3DQ
- B.
5EQ, 5DQ
- C.
4EQ, 2DQ
- D.
6EQ, 4DQ
Attempted by 289 students.
Sign up free to check your answer
Sign up freeLoading lesson…