package com.yuyong.alorithms;
public class SelectionSort {
/**
* @param args
*/
public void selectionSort(int arr[], int n) {
for (int i = 0; i < n; i++) {
// 寻找[i,n)区间范围内的最小值
int minIndex = i;
int temp;
for (int j = i + 1; j < n; j++) {
if (arr[j] < arr[minIndex]) {
minIndex = j;
}
}
temp = arr[minIndex];
arr[minIndex] = arr[i];
arr[i] = temp;
}
}
public static void main(String[] args) {
int[] a = { 10, 8, 9, 6, 7, 5, 4, 3, 1, 2 };
SelectionSort ss = new SelectionSort();
ss.selectionSort(a, 10);
for (int i = 0; i < 10; i++) {
System.out.print(a[i] + " ");
}
}
}
點擊查看更多內(nèi)容
2人點贊
評論
評論
共同學(xué)習(xí),寫下你的評論
評論加載中...
作者其他優(yōu)質(zhì)文章
正在加載中
感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦