当前位置: 首页>>代码示例>>C#>>正文


C# PriorityQueue.RemoveFirst方法代码示例

本文整理汇总了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);
                }
            }
        }
    }
开发者ID:jesconsa,项目名称:Telerik-Academy,代码行数:28,代码来源:Dijkstra.cs

示例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);
        }
开发者ID:g-yonchev,项目名称:Telerik-Academy,代码行数:23,代码来源:PriorityQueueTests.cs

示例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);
        }
开发者ID:g-yonchev,项目名称:Telerik-Academy,代码行数:24,代码来源:PriorityQueueTests.cs


注:本文中的PriorityQueue.RemoveFirst方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。