Question
A number of different sized pancakes are stacked. A sorted pancake stack is defined as having the smallest pancake on top, the second smallest pancake
A number of different sized pancakes are stacked. A sorted pancake stack is defined as having the smallest pancake on top, the second smallest pancake under the smallest pancake, etc. The only tool provided is a spatula that will flip any top partition of the stack, including the entire stack. Note that there only ever exists one stack of pancakes, not multiple smaller, independent stacks. Larger pancakes may be on top of smaller pancakes and vice versa.
Assume that an arbitrary stack of n pancakes is represented as a Python list of numbers, with each number representing the size of the pancake. When sorted, the smallest pancake (with the smallest number) will be at index 0 in the list, and the largest pancake will be at index n 1. Write a Python function named pancakeSort that expects one argument, a possibly unsorted list of numbers representing pancakes. that uses the flipping technique described above to sort the list. Please include the function/code in the answer.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started