There are two different methods to sort a stack. They are
The push and pop operations are carried out between the input_stack and the temporary_stack in such a way that the temporary stack contains the sorted input stack. The algorithm to sort a stack using another temporary stack is discussed below.
Algorithm
@@coding::1@@
The algorithm given below describes how to sort a stack using recursion .
Algorithm
sort_stack(stack)
sort_and_insert(stack, temp)
@@coding::2@@
Test case :