We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
When you use recursion, the function calls are put on a stack.
Instead of doing that, you can put the parameters of the function call on a custom stack that you represent with a deque, a list...
Then, instead of doing your recursive call, you push those parameters on your stack, do you operations, and pop your stack to go to the next set of operations.
For exemple, this is how C's standard library quicksort is implemented, you can find the source code on the internet
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Swap Nodes [Algo]
You are viewing a single comment's thread. Return to all comments →
When you use recursion, the function calls are put on a stack. Instead of doing that, you can put the parameters of the function call on a custom stack that you represent with a deque, a list...
Then, instead of doing your recursive call, you push those parameters on your stack, do you operations, and pop your stack to go to the next set of operations.
For exemple, this is how C's standard library quicksort is implemented, you can find the source code on the internet