I'm trying to solve a problem in which it would be useful to have a data structure like
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];
i.e.
- O(n) insertion
- O(1) lookup by index
but I can't see that such a thing exists? I see that there's some confusing SortedList<T,U>
and then an interface SortedList
, but neither of those are what I'm looking for.