Skip to content

Commit 08ea335

Browse files
author
ziyuruolan
committed
选择排序
1 parent c0a8b78 commit 08ea335

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package cn.byhieg.arithmetic.sort;
2+
3+
public class SelectSort {
4+
static void swap(int[] arr,int i,int j){
5+
int temp = arr[i];
6+
arr[i] = arr[j];
7+
arr[j] = temp;
8+
}
9+
10+
static void selectSort(int[] arr){
11+
for (int i = 0;i<arr.length;i++) {
12+
int minIndex = i;
13+
for (int j=i+1;j<arr.length;j++) {
14+
minIndex = arr[j]<arr[minIndex] ? j : minIndex;
15+
swap(arr,i,minIndex);
16+
}
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)