62,623
社区成员
发帖
与我相关
我的任务
分享
class SelectSort {
void selectSort(int[] sortIn) {
int i, j, temp,min=0;
for(i=0; i<sortIn.length; i++) {
for(j=i; j<sortIn.length-1; j++) {
if(sortIn[j] > sortIn[j+1]) {
//min = j+1;
if(sortIn[min] > sortIn[j+1]) {
min = j+1;
}
}
}
temp = sortIn[i];
sortIn[i] = sortIn[min];
sortIn[min] = temp;
}
}
public static void main(String[] args) {
int[] sort = {49, 38, 65, 97, 76, 13, 27, 49, 55, 4};
SelectSort ss = new SelectSort();
ss.selectSort(sort);
for(int num : sort) {
System.out.print(" " +num);
}
}
}