简单选择排序

package com.sort;

public class SelectSort {

	public static void main(String[] args) {
		int[] a = new int[]{6,5,4,3,2,1};
		selectSort(a);
		for(int array:a){
			System.out.println(array);
		}
	}

	private static void selectSort(int[] a) {
		for(int i=0; i<a.length; i++){
			int index = i;
			for(int j=i; j<a.length; j++){
				if(a[index]>a[j]){
					index = j;
				}
			}
			swap(a,i,index);
		}
	}
	
	private static void swap(int[] a, int j, int i) {
		int temp = a[j];
		a[j] = a[i];
		a[i] = temp;
	}

}

你可能感兴趣的:(简单选择排序)