Algorithms icon indicating copy to clipboard operation
Algorithms copied to clipboard

Heapsort nitpicking

Open TianyiShi2001 opened this issue 4 years ago • 0 comments
trafficstars

https://github.com/williamfiset/Algorithms/blob/039cfc4efe849228f5af224956fa45d835732efa/src/main/java/com/williamfiset/algorithms/sorting/Heapsort.java#L21-L36

  • Since you are checking n / 2 - 1 is non-negative anyways in line 27, probably it is more elegant to check n is more than 1 before that (when n is 0 or 1, the array is already sorted and we can return early)
  • At line 32 sinking index 0 is redundant.

TianyiShi2001 avatar Jun 22 '21 00:06 TianyiShi2001