排序列表,仅仅需要IComparable的< T>

排序列表,仅仅需要IComparable的< T>

问题描述:

我有一个接口 IScriptItem 实现 IComparable的< IQueueItem> 。 在我眼里这似乎足有才能有一个排序的任何 IComparable的项目。但是,所有我能找到的是字典,哈希表和SortedLists,实际上是SortedTrees。

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.

我正在寻找的是一个通用的排序列表中需要IComparables。 我是不是找错了地方?

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:

  • 使用排序列表与虚拟TValue。
  • 使用列表或数组,并调用List.Sort()或的Array.Sort()在必要的时候。
  • 在写自己的。
  • 使用第三方库

对于这种特殊情况下,检查了Wintellect的PowerCollections OrderedBag类,它采用了红黑树内部。其他良好的免费数据结构库包括NGenerics和C5。

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.