0

Selection sort in java

void SelectionSort(int arr[]) {
 for(int k = 0; k < arr.length-1; k++) {
   int min_idx = k;
   for(int j = k+1; j < arr.length; j++)
     if (arr[j] < arr[min_idx])
       min_idx = j;
           
   //swap
   int temp = arr[min_idx];
   arr[min_idx] = arr[k];
   arr[k] = temp;
 }
}

ks007

Leave a Reply

Your email address will not be published. Required fields are marked *