编辑代码

public class SelectionSort {
    public static void main(String[] args) {
        int[] arr1 = {11, 9, 3, 20, 56, 32};
        int[] arr2 = {5, 2, 9, 1, 5, 6};
        int[] arr3 = {10, 8, 6, 4, 2, 0};
        
        System.out.println("Test Case 1 (Selection Sort):");
        selectionSort(arr1);
        printArray(arr1);
        
        System.out.println("Test Case 2 (Selection Sort):");
        selectionSort(arr2);
        printArray(arr2);
        
        System.out.println("Test Case 3 (Selection Sort):");
        selectionSort(arr3);
        printArray(arr3);
    }
    
    public static void selectionSort(int[] arr) {
        int n = arr.length;
        for (int i = 0; i < n - 1; i++) {
            int minIndex = i;
            for (int j = i + 1; j < n; j++) {
                if (arr[j] < arr[minIndex]) {
                    minIndex = j;
                }
            }
            // Swap arr[i] and arr[minIndex]
            int temp = arr[i];
            arr[i] = arr[minIndex];
            arr[minIndex] = temp;
        }
    }
    
    public static void printArray(int[] arr) {
        for (int num : arr) {
            System.out.print(num + " ");
        }
        System.out.println();
    }
}