I have an interface IScriptItem
that implements IComparable<IQueueItem>
.
In my eyes it would seem enough to have IComparable
items in order to have a sorted anything. But all I can find is Dictionaries, Hashtables and SortedLists that are actually SortedTrees.
What I'm looking for is a sorted generic list that takes IComparables. Am I looking in the wrong places?
There's nothing built-in. You have some options:
For this particular case check out Wintellect PowerCollections OrderedBag class, which uses a red-black tree internally. Other good free data structure libraries include NGenerics and C5.
If I understand correctly, you want an SortedCollection< TValue> instead of the various SortedCollection< TKey, TValue> that are there.
In .NET 4 there is a new
SortedSet<T>
class that keeps its items in order, but doesn't allow duplicates. Otherwise you'll have to look at 3rd party options, like the one Matt Howells mentions.