[ Back to the overview Matrix ]

Test case : Bubble sort

Write an application that lets the user input up to 25 numbers, puts them into an array (if available), sorts them in ascending order using a simple bubble sort(*), and prints the result.
Input should give a ">" prompt and wait until the user enters a whole number between 1 and 32000, followed by "enter". The input phase ends if the user enters 0"enter" or just "enter" (supporting one is enough), or 25 numbers have been entered.
This sould be an console application.

Use a simple bubble sort following this pseudo code. Using internal or other sort algorithms is not allowed:

     
do 
  for each number from first to last 
    if number is bigger than next number
      swap number with next number 
while any number was swapped in this run

You don't have to check for any invalid input.

What is tested: Array handling (or array alternatives), simple control structures, user input, screen output.

Contributed by Andreas Koch, mail at kochandreas.com