B
Ben Bacarisse
CBFalconer said:A node*, which gives the compare function access to the next field,
and also means the compare function needs to know the definition of
a node. It doesn't need any of this, it just needs a pointer to
the const data. Mergesort doesn't need to know the form of the
data, and thus uses const void* pointers. That way errors in
writing the compare won't foul things up.
Think about it. The compare function should compare two
thingummies. It doesn't need to be a special function for the
sort. It doesn't need to know about nodes. It certainly doesn't
care where the next node is. For all you know the data may be
encoded names, needing decoding, translation, etc.
It is never quite that simple. Your interface restricts mergesort to
those lists that use indirect data. It is possible to remove this
restriction -- the simplest way is (in part) to pass node pointers to
the compare function. Passing a void * (stored in the node) is not
100% general.