UNB/ CS/ David Bremner/ teaching/ java/ BubbleSort.java
public class BubbleSort{
/**
   Swaps two elements in an array.
   @param  a    the array with the elements
   to swap
   @param  i    the index of one of the elements
   @param  j    the index of the other element
   @return
*/
    public static void swap(int[] a,
                            int i, int j){
        int temp = a[i];
        a[i] = a[j];
        a[j] = temp;
    }

    /**
       Sorts an array.
       @param a the array to sort
    */
    public static void sort(int[] a){
        boolean finished=false;

        while(!finished){
            // assume this is the last pass
            finished=true;
            for (int i=0; i<a.length-1; i++){
                if (a[i]>a[i+1]){
                    swap(a,i,i+1);
                    finished=false;
                }
            }
        }
    }

}