"Does these sorts algorithms (in Standard Library) use some of advanced sorts approaches, like bubble sort ... in their internal implementations."pic.twitter.com/G2aVVlqKBA
I usually write the version that avoids swapping to bubble down elements, which does write in every iteration of the loop. Anyway, yeah, you’re probably right that insertion sort is just as good.
-
-
Ah, sure. Presumably that optimization is less relevant for this application anyway, but it should be straightforward to do the write only when your inner loop runs for one or more iterations.
-
Oh, one reason could be that the function is sorting a singly-linked list, so it can't iterate backwards. I'm still quite skeptical of the bubble sort but the obvious algorithm I gave doesn't work in this context.
End of conversation
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.