【发布时间】:2010-11-29 16:32:31
【问题描述】:
我需要一个相当专业的 .NET 集合,我不认为 BCL 可以帮助我,但我想如果有人知道类似的东西,我会把它扔在那里。
基本上,我的要求是:
- 我有一个值对列表,例如:(3, 10), (5, 10), (3, 7), (5, 5)
- 顺序很重要,即。 (3, 10) != (10, 3)
- 单个值的重复是可以的,但应该删除重复的对(最好是静默)。
- 关键是,我需要一直对这个列表进行排序。我只对排序算法在任何时候定义的列表中的第一个值感兴趣。
所以,我希望能够做一些示例代码(正如我所设想的那样,它可能会被实现,其他符合上述要求的实现也可以):
public class Pair
{
public Pair(int first, int second)
{ First = first; Second = second; }
public int First { get; set; }
public int Second { get; set; }
}
SortedQueue<Pair> foo = new SortedQueue<Pair>((left, right) => {
return right.First - left.First;
});
foo.Add(new Pair(10, 3));
foo.Add(new Pair(4, 6));
foo.Add(new Pair(6, 15));
foo.Add(new Pair(6, 13)); // This shouldn't cause a problem
Pair current = foo.Shift(); // current = (4, 6)
【问题讨论】:
标签: c# collections