package com.who;
public class SelectSort {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
// 创建一个数组,这个数组的元素是乱序的
int[] array = { 63, 4, 24, 1, 3, 15 };
// 创建类对象
SelectSort sorter = new SelectSort();
// 调用对象的排序方法
sorter.sort(array);
}
public void sort(int[] array) {
for (int i = 1; i < array.length; i++) {
int index = 0;
for (int j = 1; j <= array.length - i; j++) {
if (array[index] < array[j]) {
index = j;
}
}
int temp = array[array.length - i];
array[array.length - i] = array[index];
array[index] = temp;
}
ShowArray(array);
}
public void ShowArray(int[] array) {
for (int i = 1; i <= array.length; i++) {
System.out.print(array[i] + " ");
}
System.out.println();
}
}
ziom
慕的地6079101
宝慕林9454223
eq361
望远
相关分类