新增选择排序算法

master
星期八 5 years ago
parent ca56a4faec
commit d81029bc76
  1. 24
      panda-code/src/main/java/org/panda/code/uitl/SortUtil.java

@ -25,4 +25,28 @@ public class SortUtil {
return arr;
}
/**
* 选择排序
* @param arr
* @return
*/
public static int[] selectSort(int[] arr){
int length = arr.length;
for (int i=0;i<length;i++){
int min = arr[i];
int index = i;
for (int j=i+1;j<length;j++){
if (min>arr[j]){
min = arr[j];
index = j;
}
}
int temp = arr[i];
arr[i] = min;
arr[index] = temp;
}
return arr;
}
}

Loading…
Cancel
Save