Open Nhungftu2 opened 2 years ago
public class SelectionSort { public static int[] selectionSort(int[] arr){ int length = arr.length; for(int i=0; i< length; i++){ int minIndex = i; int j = i+1; for(; j< length; j++){ if(arr[j]<arr[minIndex]){ minIndex = j; } } int tmp = arr[i]; arr[i]= arr[minIndex]; arr[minIndex] = tmp; } return arr; } }
public class SelectionSort { public static int[] selectionSort(int[] arr){ int length = arr.length; for(int i=0; i< length; i++){ int minIndex = i; int j = i+1; for(; j< length; j++){ if(arr[j]<arr[minIndex]){ minIndex = j; } } int tmp = arr[i]; arr[i]= arr[minIndex]; arr[minIndex] = tmp; } return arr; } }