选择排序-Java版
package com.mgj.demo001;
import org.omg.CORBA.PUBLIC_MEMBER;
/**
* 选择排序
* @author Administrator
*
*/
public class SelectionSort {
public static int[] selectionSort(int[] A ,int n){
for(int i = 0; i < A.length; i++){
int min = A[i];
int num = i;
for (int j = i + 1; j < A.length; j++) {
if (min > A[j]) {
min = A[j];
num = j;
}
}
if (num != i) {
int tmp = A[i];
A[i] = A[num];
A[num] = tmp;
}
}
return A;
}
public static void main(String[] args){
int[] arr={1,3,9,8,4,5,2};
selectionSort(arr, 7);
for (int i = 0; i < arr.length; i++) {
System.out.println(arr[i]);
}
}
}