What is the best data structure for keeping the top n elements in sort order?
问题 I am looking for a data structure which keeps the top n elements, similar to this question, but with the added requirement of maintaining sort order. Obviously I could just sort at the end but there might be a more efficient way to do it on the fly. There will only be insertions, never removals, and then an iteration through the top n elements at the end. This question is language agnostic but it will be in C# so an answer that uses native .NET collections is preferable. EDIT: I should