This is an inital lab to familiarize you with the lab techniques to be used in this class AND to refresh your memory of C++ arrays, sorting, and Visual Studio.
The Pancake Sort is a sorting technique in which the only operation allowed to rearrange the elements is to reverse the front elements of the array. We call this the flip operation as it mimics the flipping of a stack of pancakes.
The aim of this exercise is to implement a simple version of the algorithm described below. Assuming that the array is A with n elements, the algorithm will take n-1 passes.
You need to keep count on the number of times you flip the elements.
Below shows the 6 passes of this Pancake Sort algorithm on the 7-element array {5, 7, 3, 2, 10, 8, 6}. The total number of flips is 8.
Write a program pancake_sort.c
to implement this Pancake Sort algorithm on an integer array with at most 20 elements. The input of your program consists of the number of array elements followed by that number of array elements. The output of your program is the sorted array, and the number of flips performed.
You may assume that the array does not contain duplicate elements.
Sample runs using interactive input (user's input shown in blue; output shown in bold purple). Note that the first two lines (in green) below) are commands issued to compile and run your program in Visual Studio 2010.
Number of elements: 7 Enter array values: 5 7 3 2 10 8 6
Sample run #2:
Number of elements: 10 Enter array values: -14 39 7 13 52 -28 0 5 -2 10
The time here is an estimate of how much time we expect you to spend on this exercise. If you need to spend way more time than this, it is an indication that some help might be needed.
-- JimSkon - 2011-02-04