I would like to implement a priority queue which would inject my objects - Nodes
to the queue with respect to one field - f
. I have already written List with custom comparer but this would require from me to:
- enqueue - sort the List after each insertion
dequeue - remove the last(instead of first for performance) like so
myList.RemoveAt(myList.Count - 1);
My List should be always sorted according to some field (here I need it to be sorted by f
). I also need the ability to add and dequeue
the object with lowest value from the list.
Can someone tell me what would be the best approach to this ?
EDIT
dasblinkenlight has a very good answer but just I have realised that I should be able to store duplicates in this container.