本文整理汇总了C#中PriorityQueue.RemoveFirst方法的典型用法代码示例。如果您正苦于以下问题:C# PriorityQueue.RemoveFirst方法的具体用法?C# PriorityQueue.RemoveFirst怎么用?C# PriorityQueue.RemoveFirst使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PriorityQueue
的用法示例。
在下文中一共展示了PriorityQueue.RemoveFirst方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindMinimalDistance
public static void FindMinimalDistance(Dictionary<Node, List<Connection>> graph, Node source)
{
var queue = new PriorityQueue<Node>();
foreach (var node in graph)
node.Key.DijkstraDistance = long.MaxValue; // double.PositiveInfinity;
queue.AddFirst(source);
source.DijkstraDistance = 0;
while (queue.Count != 0)
{
var currentNode = queue.RemoveFirst();
// if (currentNode.DijkstraDistance == long.MaxValue) break;
foreach (var neighbour in graph[currentNode])
{
var potDistance = neighbour.Distance + currentNode.DijkstraDistance;
if (potDistance < neighbour.ToNode.DijkstraDistance)
{
neighbour.ToNode.DijkstraDistance = potDistance;
queue.AddFirst(neighbour.ToNode);
}
}
}
}
示例2: TestWithClassHumanImplementsIComparableByAge
public void TestWithClassHumanImplementsIComparableByAge()
{
// Test with class Human implements IComparable (by Age):
var priorityQueueHumans = new PriorityQueue<Human>();
priorityQueueHumans.Add(new Human("Ivan", 25));
priorityQueueHumans.Add(new Human("Georgi", 13));
priorityQueueHumans.Add(new Human("Cvetelina", 18));
priorityQueueHumans.Add(new Human("Plamena", 22));
priorityQueueHumans.Add(new Human("Gergana", 23));
priorityQueueHumans.Add(new Human("Qna", 21));
var numbersActualOrder = new List<string>();
while (priorityQueueHumans.Count > 0)
{
numbersActualOrder.Add(priorityQueueHumans.RemoveFirst().Name);
}
var numbersExpectedOrder = new List<string>() { "Georgi", "Cvetelina", "Qna", "Plamena", "Gergana", "Ivan" };
CollectionAssert.AreEqual(numbersExpectedOrder, numbersActualOrder);
}
示例3: TestWithPrimitiveType
public void TestWithPrimitiveType()
{
var priorityQueueInts = new PriorityQueue<int>();
priorityQueueInts.Add(5);
priorityQueueInts.Add(10);
priorityQueueInts.Add(-5);
priorityQueueInts.Add(1);
priorityQueueInts.Add(13);
priorityQueueInts.Add(13);
priorityQueueInts.Add(0);
priorityQueueInts.Add(25);
var numbersActualOrder = new List<int>();
while (priorityQueueInts.Count > 0)
{
numbersActualOrder.Add(priorityQueueInts.RemoveFirst());
}
var numbersExpectedOrder = new List<int>() { -5, 0, 1, 5, 10, 13, 13, 25 };
CollectionAssert.AreEqual(numbersExpectedOrder, numbersActualOrder);
}