• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests

Algorithms Quiz | SP Contest 3 | Question 4

What does the below function do in general? 

C
void fun(Queue *Q)
{
	Stack S; // Say it creates an empty stack S

	// Run while Q is not empty
	while (!isEmpty(Q))
	{
		// deQueue an item from Q and
		// push the dequeued item to S
		push(&S, deQueue(Q));
	}

	// Run while Stack S is not empty
	while (!isEmpty(&S))
	{
	// Pop an item from S and enqueue
	// the popped item to Q
	enQueue(Q, pop(&S));
	}
}

(A)

Removes the last element from the queue, Q

(B)

Keeps the queue, Q same as it was before the call

(C)

Makes queue Q empty

(D)

Reverses the queue Q

Answer

Please comment below if you find anything wrong in the above post
Feeling lost in the world of random DSA topics, wasting time without progress? It's time for a change! Join our DSA course, where we'll guide you on an exciting journey to master DSA efficiently and on schedule.
Ready to dive in? Explore our Free Demo Content and join our DSA course, trusted by over 100,000 geeks!

Last Updated :
Share your thoughts in the comments