您是否有代码只为您排序,并在完成排序后查看是否有任何更改.你会使用某种类型的排序,如插入排序,选择或沿着这些行的东西
int[] arr = {4,1,3,8,9,2,7,0,5,6};
System.out.println(Arrays.toString(arr));
selectionSort(arr);
public static void selectionSort (int []arr) {
for(int i = 0; i < arr.length; i ++) {
//find the ith element
int smallest = i;
for (int j = i + 1; j <arr.length; j++) {
//find the smallest unsorted element
if(arr[j] < arr[smallest]) {
smallest = j;
Run Code Online (Sandbox Code Playgroud)
所以我认为我在正确的轨道上,但我不知道如何比较整数,看看是否有正确的顺序.
我需要添加什么?
java ×1