選擇排序-簡單選擇排序

package com.larry.sorting;

import java.util.Arrays;

public class EasySelectSort {
	private void easySelectSort(int s[]){
		if(s == null) return;
		for(int i = 0; i < s.length; i++){
			int index = i;
			for(int j = i+1; j < s.length; j++){
				if(s[j] < s[index]) index = j;
			}
			if(index != i){
				int temp = s[i];
				s[i] = s[index];
				s[index] = temp;
			}
		}
	}
	public static void main(String[] args) {
		int s[] = {23, 13, 49, 6, 31, 19, 28};
		new EasySelectSort().easySelectSort(s);
		System.out.println(Arrays.toString(s));
	}
}

發佈了233 篇原創文章 · 獲贊 1 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章