BS Pass 3

The array is still not sorted, so we need to perform another pass. After performing the third pass the array will look like this:

ADS 03 L

Notice that after each pass the number of items guaranteed to be sorted is increased by one, but that other items may move towards their final destination. The example array is still not sorted, so we need to perform one more pass. In this pass we again start by comparing element [0] with element [1]. After performing this pass this array is now sorted.

ADS 03 M

The description above is of course only valid for the data given above. In more general terms the process can be described thus:


for number of passes
{
   for number of elements - 1
   {
      compare adjacent elements
      if elements out of order then exchange elements
   }
}

Next: BS Tasks