2 ms·
Comb sort tip --- instead of dividing by 1.3 use 1.333 (repeating) instead. In practical terms using integers, this makes almost no difference *except* it can
by jqpabc123 3y ago
Comb sort tip --- instead of dividing by 1.3 use 1.333 (repeating) instead.
In practical terms using integers, this makes almost no difference *except* it can be performed using faster shift and add operations:
gap = ((gap << 1) + gap) >> 2;
For even more speed, I'd also recommend in-lining this to eliminate the function call. Properly implemented, respectable speed can be achieved from a really trivial implementation.