• Welcome to Valhalla Legends Archive.
 

Doubly Linked List - Request for comments

Started by Telos, November 22, 2003, 07:08 PM

Previous topic - Next topic

Eibro

No they wouldn't. Take std::list for example.
You'll need to remove case sensitivity, since this only makes sense for strings alike. Use operators < > == in the InsertInOrder function. The user will need to overload these operators for their type in order to use the InsertInOrder function.

Or you could go the route of std::sort and accept a function or functor for the purposes of comparison.
Eibro of Yeti Lovers.

iago

What if they just want to put in int's, or some other type?

In Java, you could just use the interface Comparable, but this isn't Java.  

I still think the best way is either to not sort it or to use an abstract class for data.
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


Adron

Inserting items in order into a linked list is a bad idea anyway; a list is no good for sorting. A skiplist or a tree would work better.

If you absolutely want to sort the list anyway, do like Eibro suggests. I see no problem at all with just sorting based on the regular operators, < > =, applied to the items. Those operators exist for the built-in types, and if you want to make a sorted list of some class all you have to do is define the comparison operators for that class.