Posted on 2008-02-26 08:54
KAY 阅读(420)
评论(0) 编辑 收藏
public class SortTest {
public static void main(String[] args) {
int[] values = { 3, 1, 6, 2, 9, 0, 7, 4, 5 };
sort(values);
for (int i = 0; i < values.length; i++) {
System.out.println(values[i]);
}
}
public static void sort(int[] values) {
int temp;
for (int i = 0; i < values.length; i++) {
for (int j = 0; j < values.length - i - 1; j++) {
if (values[j] > values[j + 1]) {//可以在这里调整排序是ASC or DESC
temp = values[j];
values[j] = values[j + 1];
values[j + 1] = temp;
}
}
}
}
}