Possible Duplicate:
Fibonacci, Binary, or Binomial heap in c#?
Is there any class like heap in .NET?
I need some kind of collection from which I can retrieve min. element. I just want 3 methods:
Add()RemoveMinElement()GetMinElement()
I can’t use sorted list because there keys has to be unique, and I might have several identical elements.
You could use
SortedListor aSortedDictionary(see discussion below) with a custom key. If you used a type with referential equality, but could be compared based on the value you care about, then this could work.Something like this:
Here is a working example of using a
SortedDictionarywhich has binary-heap performance characteristics:Results: