Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class PriorityQueue
- {
- // I'm using an unsorted array for this example, but ideally this
- // would be a binary heap. Find a binary heap class:
- // * https://bitbucket.org/BlueRaja/high-speed-priority-queue-for-c/wiki/Home
- // * http://visualstudiomagazine.com/articles/2012/11/01/priority-queues-with-c.aspx
- // * http://xfleury.github.io/graphsearch.html
- // * http://stackoverflow.com/questions/102398/priority-queue-in-net
- private List<NodeElement> elements = new List<NodeElement>();
- public List<NodeElement> elementstoremove = new List<NodeElement>();
- public int Count
- {
- get { return elements.Count; }
- }
- public void Enqueue(NodeElement next, double priority)
- {
- next.passed = true;
- next.priority = priority;
- elements.Add(next);
- elementstoremove.Add(next);
- }
- public NodeElement Dequeue()
- {
- int bestIndex = 0;
- for (int i = 0; i < elements.Count; i++)
- {
- if (elements[i].priority < elements[bestIndex].priority)
- {
- bestIndex = i;
- }
- }
- NodeElement bestItem = elements[bestIndex];
- elements.RemoveAt(bestIndex);
- return bestItem;
- }
- }
Add Comment
Please, Sign In to add comment