Advertisement
DulcetAirman

sort half of array

Apr 30th, 2021
683
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. static void halfSort(final int[] a) {
  2.       for (int i = 0; i < a.length / 2; i++) {
  3.         var lowestIndex = -1;
  4.         var lowestValue = -1;
  5.         for (int j = i; j < a.length; j++) {
  6.             if(lowestIndex == -1 || a[j] < a[lowestIndex]) {
  7.                 lowestIndex = j;
  8.                 lowestValue = a[j];
  9.             }
  10.         }
  11.         System.arraycopy(a, i, a, i+1, lowestIndex-i);
  12.         a[i] = lowestValue;
  13.       }
  14.   }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement