DulcetAirman icon

sort half of array

DulcetAirman | PRO | 04/30/21 11:36:00 AM UTC | 0 ⭐ | 1284 👁️ | Never ⏰ | []
Java |

360 B

|

None

|

0 👍

/

0 👎

static void halfSort(final int[] a) {
      for (int i = 0; i < a.length / 2; i++) {
        var lowestIndex = -1;
        var lowestValue = -1;
        for (int j = i; j < a.length; j++) {
            if(lowestIndex == -1 || a[j] < a[lowestIndex]) {
                lowestIndex = j;
                lowestValue = a[j];
            }
        }
        System.arraycopy(a, i, a, i+1, lowestIndex-i);
        a[i] = lowestValue;
      }
  }

Comments