Bubblesort

Objective

In this experiment, you need to follow the Bubblesort algorithm by stepping through it.

Experiment Setup

In this experiment, there is just one control called Next. The machine now has another state variable b, called the boundary variable, which keeps track of the portion of the list already sorted.

The Next button performs the next step in the Bubblesort algorithm. The next step advances the variable i, ordering the element at i and its right neighbour. It resets i if i reaches b-1 and also decrements b.

Procedure

Follow the given steps to perform the experiment.

  1. Click on the Next button to step through the algorithm.
  2. When the boundary reaches the value 1, check if the list is sorted.