generalize reverseSort