/* BubbleSort.java
 *
 * This version of sort thread implements Bubble Sort. It is called
 * by the ClassNotes+ Demo package.
 */

class BubbleSort extends CNSortAlgorithm {

  /**
   * Implementation of Bubble sort.
   */
  void sort(SortItem array[], int num_elems) {
     boolean sorted;
     sorted = false;
     while ( ! sorted ) {
       sorted = true; 
       for (int j = 0; j < num_elems - 1; j++) {
 	 demo.highlightElement(j+1);
         if (array[j].getValue() > array[j+1].getValue()) {
           demo.swap(j, j+1);
           demo.pause(demo.BLOCK_SINGLE_STEP);
           sorted = false;
         }
       }
       demo.pause(demo.BLOCK_LOOP);
     }
  }
} /* end BubbleSort */

