手记

java简单排序算法实现


public class SimpleSort {
	
	public static void sort(int[] arr) {
		int n  = arr.length;
		
		for(int i = 0 ; i < n ;i ++) {
			int k = i;
			for(int j = i+1;j < n; j++) {
				if(arr[j] < arr[k]) {
					k = j ;
				}
			}
			if(k > i) {
				int temp = arr[i];
				arr[i] = arr[k];
				arr[k] = temp;
			}
			
		}
	}
	public static void main(String[] args) {
		  int[] b = { 49, 38, 65, 97, 76, 13, 27, 50 };
		  sort(b);
	        for (int i : b)
	            System.out.print(i + " ");
	    }
	

}

result : 13 27 38 49 50 65 76 97

1人推荐
随时随地看视频
慕课网APP