I found an implementation of algorithm in c++ here https://gist.github.com/andlima/1774060 but I don't understand a purpose of few lines and how they work,
I'll be really really grateful for any help with this.
N
, add N-1
before the division.if
condition checks if the chunk has five elements. The for
loops inside perform a selection sort, swapping elements to place the median at index w[2]
medians
as soon as the recursive invocation is over, because the rest of the algorithm does not need it.pivot
to the end position of the array.