/**
 * A library for sorting lists of integers
 *
 * @version	$Id: Sort.java,v 1.1 2003/09/30 20:29:16 nthiery Exp $
 * @author	Nicolas M. Thiéry <nthiery@users.sourceforge.net>
**/

public class Sort {

    /**
     * Sort anArray using bubble sort
     *
     * @param anArray	an array of integers
     * @return		anArray sorted
     **/

    public static int[] bubbleSort(int[] anArray) {
	for (int i=1; i < anArray.length; i++) {
	    // Invariant: anArray[0..i-1] is already sorted.
	    for (int j=i; j>0; j--) {
		if (anArray[j-1] > anArray[j]) {
		    int tmp = anArray[j];
		    anArray[j] = anArray[j-1];
		    anArray[j-1] = tmp;
		}
	    }
	}
	return anArray;
    }
}
