Sorting a stack