Nhungftu2 / cautrucdulieu-giaithuat

0 stars 0 forks source link

Sellection sort #2

Open Nhungftu2 opened 2 years ago

Nhungftu2 commented 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; } }