wiz-icon
MyQuestionIcon
MyQuestionIcon
1
You visited us 1 times! Enjoying our articles? Unlock Full Access!
Question

Suppose you are given an implementation of a queue of integers. The operations that can be performed on the queue are:

(i) is Empty (Q) : returns true if the queue is Empty, false otherwise.
(ii) delete (Q) : delete the elements at the front of the queue and returns its value.
(iii) insert (Q, i) : insert the integer i at the rear of the queue.

Consider the following functions:

void f (queue Q)
{
int i;
if (! is Empty (Q))
{
i = delete (Q);
f(Q);
insert (Q, i);
}
}

What operation is performed by the above function f?

A
Empty the queue Q
No worries! We‘ve got your back. Try BYJU‘S free classes today!
B
Leave the queue Q unchanged
No worries! We‘ve got your back. Try BYJU‘S free classes today!
C
Delete the element at the front of the queue Q and insert it at the rear keeping the other elements in the same order
No worries! We‘ve got your back. Try BYJU‘S free classes today!
D
Reverse the order of the elements in the queue Q
Right on! Give the BNAT exam to get a 100% scholarship for BYJUS courses
Open in App
Solution

The correct option is D Reverse the order of the elements in the queue Q
Case - 1 : When queue is empty then no change would happen on queue.

Case - 2 : 1st delete all elements one by one from queue then last deleted element enter at 2nd position, etc.
So finally we get reverse order of given input queue.

flag
Suggest Corrections
thumbs-up
1
similar_icon
Similar questions
View More
Join BYJU'S Learning Program
similar_icon
Related Videos
thumbnail
lock
Permutations
MATHEMATICS
Watch in App
Join BYJU'S Learning Program
CrossIcon