Java选择排序

选择排序

这次我要写关于选择排序的代码。
※这是我用于自己输出的文章,请指出任何错误。

public class SelectionSort {
    public static void main(String args[]) {
        int[] array = {2,3,5,4,1};
        sort(array);
        for(int i=0;i<array.length;i++) {
            System.out.print(array[i]);
        }
    }

    public static void sort(int[] array) {
        int n = array.length;
        for (int i =0;i<n-1;i++) {
            int lowest = i;
            int lowkey = array[i];
            for(int j=i+1;j<n;j++) {
                if(array[j]<lowkey) {
                    lowest = j;
                    lowkey=array[j];
                }
            }
            int temp = array[i];
            array[i]=array[lowest];
            array[lowest] = temp;
        }
    }
}


我打算下次尝试插入排序。