【发布时间】:2017-06-13 21:55:44
【问题描述】:
我正在尝试解决一个问题,在该问题中拥有像
这样的数据结构会很有用var list = new SortedList<int>();
list.Add(3); // list = { 3 }
list.Add(1); // list = { 1, 3 }
list.Add(2); // list = { 1, 2, 3 }
int median = list[list.Length / 2];
即
- O(n) 次插入
- O(1) 按索引查找
但我看不出有这样的东西存在?我看到有一些令人困惑的SortedList<T,U>,然后是一个界面SortedList,但这些都不是我想要的。
【问题讨论】:
-
@PetSerAl 对不起,我的意思是 O(n) 插入。我的错。
-
您可以随时尝试make one yourself。
标签: c# .net algorithm data-structures