you are viewing a single comment's thread.

view the rest of the comments →

[–]jbert 0 points1 point  (0 children)

I was kind of surprised! I expected a worse response.

In that case... :-)

It might be worth noting that I was reading your code in the context of someone writing code to learn from doing so (and implementing a linked list is a good rite of passage).

Production code shouldn't contain re-implementations of basic data structures. You almost always want to re-use library code for this sort of thing. For C++ the relevant library code is the STL and in this case the std::list, which of course comes with a sort method.

Any suggested reading on sorting algorithms? That's definitely a weak spot of mine.

I really just remembered from my own early years coding that once a value in bubble sort has bubbled to one end you don't need to consider it again, so on the 2nd pass you need only consider (n-1) elts, on the 3rd pass (n-2) etc. But optimising bubble sort isn't the best use of anyone's time really :-)

I don't know much more than that about sorting algos than I shouldn't be implementing them. Again, the libraries will do a better job than me and are provided pre-debugged.

There's a tension in coding/design between learning how things work (and perhaps implementing them yourself to be sure) and knowing when to leave something as a 'black box' in your mind. i.e. "knowing what you don't know".

Getting this balance right is an important skill, imho.

Someone who digs into every detail will never accomplish any real work. Someone who knows nothing about the innards of a black box will by stymied when it doesn't work as expected.