forked from hansiming/JavaProject
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSelectSort.java
More file actions
37 lines (28 loc) · 558 Bytes
/
SelectSort.java
File metadata and controls
37 lines (28 loc) · 558 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
package com.csdhsm.sort;
/**
* @Title: SelectSort.java
* @Package: com.csdhsm.sort
* @Description 选择排序
* @author Han
* @date 2016-4-3 下午3:44:33
* @version V1.0
*/
public class SelectSort {
public void sort(int[] arr,int len){
for(int i=0;i<len-1;i++){
//记录最小元素的下标
int min = i;
for(int j=i+1;j<len;j++){
if(arr[j] < arr[min]){
min = j;
}
}
/**
* 将最小值交换至前端
*/
int temp = arr[i];
arr[i] = arr[min];
arr[min] = temp;
}
}
}