views:

225

answers:

1

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?

+2  A: 

There's nothing built-in. You have some options:

  • Use SortedList with a dummy TValue.
  • Use a list or array and call List.Sort() or Array.Sort() when necessary.
  • Write your own.
  • Use a third party library

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.

Matt Howells
Am I the only one that thinks it's weird that such a basic thing doesn't exist?
borisCallens
I think the number and variety of built-in data structures is shockingly poor, yes.
Matt Howells