public class Paixu {
public static void main(String[] args) {
int [] a = {2,6,4,5,1,7,3};
int i = 0;
int j = 0;
int n = 0;
for(i= 0;i
n = a[j];
a[j] = a[j+1];
a[j+1] = n;
}
}
}
for ( i = 0; i < a.length; i++) {
System.out.println(a[i]);
}
}
}
直接选择排序(Straight Select Sorting) 也是一种简单的排序方法,它的基本思想是:第一次从R[0]~R[n-1]中选取最小值,与R[0]交换,第二次从R{1}~R[n-1]中选取最小值,与R[1]交换,...., 第i次从R[i-1]~R[n-1]中选取最小值,与R[i-1]交换,.....,第n-1次从R[n-2]~R[n-1]中选取最小值,与R[n-2]交换,总共通过n-1次,得到一个按排序码从小到大排列的有序序列.
public class Paixu {
public static void main(String[] args) {
int [] a = {2,6,4,5,1,7,3};
int i = 0;
int j = 0;
int n = 0;
for(i= 0;i
n = a[i];
a[j] = a[i];
a[i] = n;
}
}
}
for ( i = 0; i < a.length; i++) {
System.out.println(a[i]);
}
}
}