sorting prefix reversal in sorting a pile of pancakes problem