public class Sort {
// 冒泡排序
@Test
public void demo1() {
int[] arr = { 1, 2, 5, 4, 1, 3, 6, 598, 25, 145, 2, 5 };
for (int i = 0; i < arr.length - 1; i++) {
int minindex = i;
for (int j = i + 1; j < arr.length; j++) {
if (arr[minindex] > arr[j]) {
minindex = j;
}
}
if (minindex != i) {
int temp = arr[i];
arr[i] = arr[minindex];
arr[minindex] = temp;
}
}
System.out.println(Arrays.toString(arr));
}
} |
|