![]() |
VOOZH | about |
Given an array of elements, the task is to sort these elements using a stack.
Prerequisites: Stacks
Examples:
Input : 8 5 7 1 9 12 10 Output : 1 5 7 8 9 10 12 Explanation : Output is sorted element set Input : 7 4 10 20 2 5 9 1 Output : 1 2 4 5 7 9 10 20
We basically use Sort a stack using a temporary stack. Then we put sorted stack elements back to the array.
Implementation:
5 10 15 45
Complexity Analysis: