FileDocCategorySizeDatePackage
BubbleSortThread.javaAPI DocExample1263Mon May 03 23:36:48 BST 2004com.oreilly.tiger.ch10

BubbleSortThread

public class BubbleSortThread extends Thread

Fields Summary
private int[]
numbers
Constructors Summary
public BubbleSortThread(int[] numbers)

    setName("Simple Thread");
    setUncaughtExceptionHandler(
      new SimpleThreadExceptionHandler());
    this.numbers = numbers;
  
Methods Summary
public voidrun()

    int index = numbers.length;
    boolean finished = false;
    while (!finished) {
      index--;
      finished = true;
      for (int i=0; i<index; i++) {
        // Create error condition
        if (numbers[i+1] < 0) {
          throw new IllegalArgumentException(
            "Cannot pass negative numbers into this thread!");
        }

        if (numbers[i] > numbers[i+1]) {
          // swap
          int temp = numbers[i];
          numbers[i] = numbers[i+1];
          numbers[i+1] = temp;

          finished = false;
        }
      }
    }