/**
* 功能是实现选择排序
**/
package pro2;
public class work3 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int arr[]={1,2,5,7,0,6,8};
choose Choose = new choose();
Choose.sort(arr);
}
}
class choose {
public void sort(int arr[]) {
int temp = 0;
for (int j = 0; j < arr.length - 1; j++) { // 标记最小数组和元素
int minnumber = arr[j];
int min = j;
for (int k = j + 1; k < arr.length; k++) {
if (minnumber > arr[k]) { // 赋给他们最小值
minnumber = arr[k];
min = k;
}
// 交换值
temp = arr[j];
arr[j] = arr[min];
arr[min] = temp;
}
}
for (int i = 0; i < arr.length; i++) {
System.out.print(arr + " ");
}
}
}
qq_青枣工作室_0
相关分类