Pancake sorting implementation