CPS 49S: Sorting

Gele Moloney and Carolyn Robinson



Starting with rectangle one and two, compare the heights and determine which is taller. Move the taller rectangle to the left. If the taller rectangle is already on the left, start comparing the rectangle to it's immediate left. Determine which rectangle is taller. Move the taller rectangle to the left. If rectangle three is taller than the rectangle to its immediate left compare rectangle three to the rectangle on the farthest left. Repeat this process of comparing and moving and then comparing again until all rectangles have been placed in order of height. Stop moving the rectangle when it has reached a rectangle that is taller.