-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSectionSort
48 lines (40 loc) · 1.29 KB
/
SectionSort
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
42
43
44
45
46
47
48
package yexin.java.base;/**
* Company: Huazhong University of science and technology
* 华中科技大学电气学院聚变与等离子体研究所
* Version: V1.0
* Author: Victor
* Contact: [email protected] 2018--2020
* Software: IntelliJ IDEA
* File: SelectionSort
* Time: 2019/2/25 19:37
* Desc:
**/
public class SelectionSort {
public static void main(String[] args) {
int[] intArray = {12,45,2,3,78,34,1,9,5};
System.out.println("排序之前的数组:");
for(int a : intArray){
System.out.print(a+" ");
}
System.out.println();
int tmp = 0;
for(int i=0;i < intArray.length;i++){
int currenNum = intArray[i];
int index = i;
for(int j=i;j < intArray.length;j++){
if(intArray[j] < currenNum){
index = j;
currenNum = intArray[j];
}
}
//找到最大的拿出来进行交换,而不知在里面比较交换,否则是冒泡怕排序。
tmp = intArray[i];
intArray[i] = intArray[index];
intArray[index] = tmp;
}
System.out.println("排序后的数组:");
for(int b:intArray){
System.out.print(b+" ");
}
}
}