0

Is there a C# data structure that does the followings :

  • Find max,min in O(1).
  • Delete and insert in O(logN);
  • FindNext(int var) : the smallest element that is larger than var in O(logN);
  • FindPrevious(int) : reverse of FindNext(int)
  • Can be iterated through in O(NlogN) (not important)

Obviously we can do all of those with std::set. Is there anything in C# that can do the same?

David Mahone
  • 245
  • 1
  • 7
  • Duplicate: http://stackoverflow.com/questions/575406/what-is-the-c-sharp-equivalent-of-the-stl-set & http://stackoverflow.com/questions/2658761/is-there-an-equivalent-of-stdset-in-c – RJ Lohan Jun 21 '13 at 01:15
  • @RJLohan Note that a `SortedSet`, which is the main answer given to both of those questions, doesn't have an equivalent to `FindNext` or `FindPrevious`. In theory they can be done with the requested efficiency on a binary search tree, which is what std:set is, but the .NET library chose not to expose those operations, nor enough of the underlying structure to implement it yourself as an extension. It gives you the rest of it though. – Servy Jun 21 '13 at 14:58
  • @Servy That is really unfortunate. Having a binary tree and coulnd't perform a binary search, which is essentially what FindNext and FindPrevious is about. Do you know what is the reason behind choosing not to expose these APIs? – David Mahone Jun 25 '13 at 23:08

0 Answers0