suppose we have stack s1 (which is to sort) and an additional stack s2. In each round, we move elements from s1 to s2, and record the maximum element(curmax) in s1. then we move elements back to s1 using the following rule:
1)if current top of s2 is equal to curmax, increase a counter by 1
2)if the current top of s2 is not equal to curmax, push it into s1
after iteration of s2, push curmax counter times to s2
when s1 is empty, we move all elements from s2 to s1, and the maximum element is at the top of s1.
average time complexity O(n^2), in the best case(all elements are equal) time complexity is O(n)