数据结构与算法-----选择排序-----直接选择排序
程序员文章站
2022-07-08 16:03:09
...
package jzoffer;
public class DirectSelectionSort {
public static void main(String[] args) {
int [] R = {10,9,8,7,6,5,4,3,2,1};
System.out.println("原始数组如下:");
printList(R);
DirectSelectionSort(R);
System.out.println("经过直接选择排序后数组如下:");
printList(R);
}
private static void printList(int [] a){
for(int i =0;i<a.length;i++){
System.out.print(a[i]+" ");
}
System.out.println("");
}
public static void DirectSelectionSort(int [] str){
int min = 0;
for(int i = 0;i<str.length-1;i++){
min = str[i];
for(int j =i+1;j<str.length;j++){
if(str[i] > str[j]){
min = str[j];
str[j] = str[i];
str[i] = min;
}
}
}
}
}
下一篇: PC与移动之争:谁将主导VR的未来?