-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSortTest.java
More file actions
41 lines (36 loc) · 827 Bytes
/
Copy pathSortTest.java
File metadata and controls
41 lines (36 loc) · 827 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
* 作者:张启卫
* 时间:2016年9月24号
* 功能:数组选择排序算法
*/
public class SortTest{
public static void main(String[] args){
int[] intarray = {1,23,45,66,2,332,8,5};
int keyvalue;
int index;
int temp;
System.out.println("排序前的数组元素");
for(int i : intarray){
System.out.print(i + " ");
}
System.out.println();
//选择排序算法
for(int i = 0; i < intarray.length; i++){
index = i;
keyvalue = intarray[i];
for(int j=i+1; j < intarray.length; j++){
if(intarray[j] < keyvalue){
index = j;
keyvalue = intarray[j];
}
}
temp = intarray[i];
intarray[i] = intarray[index];
intarray[index] = temp;
}
System.out.println("排序后的数组元素");
for(int i : intarray){
System.out.print(i + " ");
}
}
}