added algorithm to sort the stack.