Sorting

Sorting, that is ordering a collection of objects in ascending or descending order, is something that often needs to be done when writing large programs. In this lesson, you will teach Reeborg some sorting skills.

Sorting two columns

As a warming up exercise, write a program so that Reeborg will arrange, or sort, two vertical piles of beepers. Here are two typical situations:

sorting start leads tosorting end




sorting start leads tosorting end

How difficult would it be to change your program so that the piles are sorted in descending order?

Sorting many columns

The following exercise is quite a bit more challenging. You have to write a program so that Reeborg will sort an unknown number of vertical piles of beepers into ascending order. The first empty pile marks the end of the piles that need to be sorted. Here's a typical example.

sorting start

leads tosorting end

How difficult would it be to change your program to sort the piles into descending order?

previous After the storm. - home - Avoiding repetitions - the important stuff next
../images/SourceForge.net Logo