beginning greedy sorting, sorting reversal working