Can We Use Queue for Recursion?
Given a queue and the task is to sort it using recursion without using any loop. We can only use the following functions of queue: empty(q): Tests whether the queue is empty or not. push(q): Adds a new element to the queue.

Can queue be used for recursion?

Recursive Algorithm :

The pop element from the queue if the queue has elements otherwise return empty queue. Call reverseQueue function for the remaining queue. Push the popped element in the resultant reversed queue.

Is recursion a queue or stack?

Many programming languages implement recursion by means of stacks. Generally, whenever a function (caller) calls another function (callee) or itself as callee, the caller function transfers execution control to the callee.
Robert Thorne

Robert Thorne

Automotive & Future Transportation Editor

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.

Share this article
Twitter Facebook Pinterest