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().
1 Réponse
+ 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.