Given a stack, sort it using recursion. Use of any loop constructs like while, for..etc is not allowed.? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Given a stack, sort it using recursion. Use of any loop constructs like while, for..etc is not allowed.?

only can use stack functions pop(), push(),top().

28th Oct 2016, 4:48 AM
lokesh
lokesh - avatar
1 Answer
+ 2
Research about Merge Sort. the logic behind this algorithm is: Organize(list) { divide the list in two; if left side not organized { organize(left side); //recursion } if right side not organized { organize(right side); //recursion } merge both sides; } this is some pseudocode, but covers basically how this algorithm works. I leave the implementation to you.
23rd Nov 2016, 9:36 PM
Alejandro Aristizabal
Alejandro Aristizabal - avatar