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


C# PriorityQueue.Peek方法代码示例

本文整理汇总了C#中System.Collections.Generic.PriorityQueue.Peek方法的典型用法代码示例。如果您正苦于以下问题:C# PriorityQueue.Peek方法的具体用法?C# PriorityQueue.Peek怎么用?C# PriorityQueue.Peek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Collections.Generic.PriorityQueue的用法示例。


在下文中一共展示了PriorityQueue.Peek方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestBasicFunctionality

        public void TestBasicFunctionality()
        {
            var q = new PriorityQueue<int>();
            Assert.AreEqual(0, q.Count);
            Assert.AreEqual(0, q.Capacity);
            Assert.Throws<InvalidOperationException>(() => q.Peek());
            Assert.Throws<InvalidOperationException>(() => q.Dequeue());

            q.Enqueue(5);
            q.Enqueue(2);
            q.Enqueue(4);

            Assert.AreEqual(3, q.Count);
            Assert.IsTrue(q.Capacity >= 3);

            Assert.IsTrue(q.Contains(2));
            Assert.IsFalse(q.Contains(3));

            Assert.AreEqual(3, q.ToArray().Length);
            CollectionAssert.AreEqual(q.ToArray(), q);

            Assert.AreEqual(2, q.Peek());

            Assert.AreEqual(2, q.Dequeue());
            Assert.AreEqual(4, q.Dequeue());
            Assert.AreEqual(5, q.Dequeue());
        }
开发者ID:GHScan,项目名称:DailyProjects,代码行数:27,代码来源:PriorityQueueTest.cs

示例2: Clear

 public void Clear()
 {
     var pq = new PriorityQueue<int>(new int[] { 1, 2, 3 });
     int temp;
     Assert.AreEqual(3, pq.Count);
     Assert.IsTrue(pq.Peek(out temp));
     pq.Clear();
     Assert.AreEqual(0, pq.Count);
     Assert.IsFalse(pq.Peek(out temp));
 }
开发者ID:sq,项目名称:Fracture,代码行数:10,代码来源:PriorityQueueTests.cs

示例3: PriorityQueuePeekQueueNoChangeInCount

        public void PriorityQueuePeekQueueNoChangeInCount()
        {
            var q = new PriorityQueue<int>();

            q.Enqueue(AnyInt);
            var count = q.Count;
            q.Peek();
            Assert.Equal(count, q.Count);
        }
开发者ID:beomyeol,项目名称:reef,代码行数:9,代码来源:TestPriorityQueue.cs

示例4: Peek

 public void Peek()
 {
     var pq = new PriorityQueue<int>(new int[] {1, 2, 3});
     int temp;
     Assert.IsTrue(pq.Peek(out temp));
     Assert.AreEqual(1, temp);
     Assert.AreEqual(1, pq.Dequeue());
     Assert.IsTrue(pq.Peek(out temp));
     Assert.AreEqual(2, temp);
 }
开发者ID:sq,项目名称:Fracture,代码行数:10,代码来源:PriorityQueueTests.cs

示例5: PriorityQueueClearEmptiesTheQueue

        public void PriorityQueueClearEmptiesTheQueue()
        {
            var q = new PriorityQueue<int>();
            q.Enqueue(AnyInt);
            q.Enqueue(AnyInt);
            q.Clear();

            Assert.Equal(0, q.Count);

            Assert.Throws<InvalidOperationException>(() => q.Peek());
        }
开发者ID:beomyeol,项目名称:reef,代码行数:11,代码来源:TestPriorityQueue.cs

示例6: DijkstraAlgorithm

        static void DijkstraAlgorithm(Dictionary<Node, List<Connection>> graph, Node source)
        {
            PriorityQueue<Node> queue = new PriorityQueue<Node>();

            foreach (var node in graph)
            {
                if (source.ID != node.Key.ID)
                {
                    node.Key.DijkstraDistance = double.PositiveInfinity;
                    queue.Enqueue(node.Key);
                }
            }

            source.DijkstraDistance = 0.0d;
            queue.Enqueue(source);

            while (queue.Count != 0)
            {
                Node currentNode = queue.Peek();

                if (currentNode.DijkstraDistance == double.PositiveInfinity)
                {
                    break;
                }

                foreach (var neighbour in graph[currentNode])
                {
                    double potDistance = currentNode.DijkstraDistance + neighbour.Distance;

                    if (potDistance < neighbour.Node.DijkstraDistance)
                    {
                        neighbour.Node.DijkstraDistance = potDistance;
                    }
                }

                queue.Dequeue();
            }
        }
开发者ID:quela,项目名称:myprojects,代码行数:38,代码来源:Dijkstra.cs

示例7: TestPeek1

        public void TestPeek1()
        {
            var queue = new PriorityQueue<string> { "string", "anotherString" };

            var poll = queue.Peek();

            Assert.AreEqual(2, queue.Count);
            Assert.AreEqual("anotherString", poll);
            Assert.IsTrue(queue.Contains("anotherString"));
        }
开发者ID:pkubryk,项目名称:SummerBatch,代码行数:10,代码来源:PriorityQueueTest.cs

示例8: DequeueTestString

        public void DequeueTestString([PexAssumeUnderTest]List<string> elementList)
        {
            PriorityQueue<string> actual = new PriorityQueue<string>(elementList);

            string dequeuedElem = actual.Dequeue();
            elementList.Sort();
            PexAssert.AreEqual(elementList[0], dequeuedElem);
            if (elementList.Count > 1)
                PexAssert.AreEqual(elementList[1], actual.Peek());
            PexAssert.AreEqual(elementList.Count - 1, actual.Count);
        }
开发者ID:taoxiease,项目名称:asegrp,代码行数:11,代码来源:PriorityQueueTest.cs

示例9: PriorityQueuePeekEmptyQueueThrowsException

 public void PriorityQueuePeekEmptyQueueThrowsException()
 {
     var q = new PriorityQueue<int>();
     Assert.Equal(0, q.Count);
     Assert.Throws<InvalidOperationException>(() => q.Peek());
 }
开发者ID:beomyeol,项目名称:reef,代码行数:6,代码来源:TestPriorityQueue.cs

示例10: TestPeek2

        public void TestPeek2()
        {
            var queue = new PriorityQueue<string>();

            var poll = queue.Peek();

            Assert.IsNull(poll);
        }
开发者ID:pkubryk,项目名称:SummerBatch,代码行数:8,代码来源:PriorityQueueTest.cs

示例11: SimpleTest

        public void SimpleTest()
        {
            var queue = new PriorityQueue<int, int>();
            
            Assert.IsFalse(queue.HasItems);
            
            queue.Enqueue(1, 10);
            queue.Enqueue(3, 30);
            queue.Enqueue(5, 50);
            queue.Enqueue(4, 40);
            queue.Enqueue(2, 20);

            Assert.IsTrue(queue.HasItems);
            Assert.AreEqual(50, queue.Peek());
            Assert.AreEqual(50, queue.Peek());
            Assert.AreEqual(50, queue.Dequeue());

            Assert.AreEqual(40, queue.Peek());
            Assert.AreEqual(40, queue.Dequeue());

            Assert.IsTrue(queue.HasItems);
            Assert.AreEqual(30, queue.Peek());
            Assert.AreEqual(30, queue.Peek());
            Assert.AreEqual(30, queue.Peek());
            Assert.AreEqual(30, queue.Dequeue());

            Assert.IsTrue(queue.HasItems);
            Assert.AreEqual(20, queue.Peek());
            Assert.AreEqual(20, queue.Dequeue());

            Assert.AreEqual(10, queue.Peek());
            Assert.AreEqual(10, queue.Peek());
            Assert.AreEqual(10, queue.Peek());
            Assert.AreEqual(10, queue.Peek());
            Assert.AreEqual(10, queue.Peek());
            Assert.IsTrue(queue.HasItems);
            Assert.AreEqual(10, queue.Peek());
            Assert.AreEqual(10, queue.Dequeue());

            Assert.IsFalse(queue.HasItems);
        }
开发者ID:VictorHaydin,项目名称:PriorityQueue.Net,代码行数:41,代码来源:Tests.cs

示例12: TestPeek

 public void TestPeek()
 {
     PriorityQueue<int, int> q = new PriorityQueue<int, int>();
     q.Enqueue(2, 2);
     q.Enqueue(1, 1);
     Assert.AreEqual(1, q.Peek());
     Assert.AreEqual(2, q.Count);
 }
开发者ID:anddudek,项目名称:anjlab.fx,代码行数:8,代码来源:PriorityQueueTests.cs

示例13: PeekTest

        public void PeekTest()
        {
            PriorityQueue<int> actual = new PriorityQueue<int> { 12, 6, 3, 1, 0, 8 };

            Assert.AreEqual(0, actual.Peek());
        }
开发者ID:robertrancz,项目名称:dsa,代码行数:6,代码来源:PriorityQueueTest.cs

示例14: ReInsert

 protected virtual void ReInsert(Node node, Int32 level)
 {
     MinimumBoundingBox nodeBox = node.CalculateMinimumBoundingBox();
     PriorityQueue<NodeEntry, Single> distances = new PriorityQueue<NodeEntry, Single>(),
     reInsertions = new PriorityQueue<NodeEntry, Single>();
     foreach (NodeEntry entry in node.NodeEntries)
         distances.Enqueue(entry, GetCenterDistance(nodeBox, entry.MinimumBoundingBox) * -1);
     for (int i = 0; i < Constants.NODES_FOR_REINSERT; i++)
         reInsertions.Enqueue(distances.Peek().Value, distances.Dequeue().Priority * -1);
     foreach (PriorityQueueItem<NodeEntry, Single> entry in reInsertions)
         node.RemoveNodeEntry(entry.Value);
     AdjustTree(node, level);
     while(reInsertions.Count > 0)
         Insert(reInsertions.Dequeue().Value, level);
 }
开发者ID:joaofig,项目名称:r-tree-csharp-framework,代码行数:15,代码来源:R_Star_Tree.cs

示例15: MaxValuesHavePriorityTest

        public void MaxValuesHavePriorityTest()
        {
            PriorityQueue<int> actual = new PriorityQueue<int>(Strategy.Max) { 6, 1, 8, 9, 2, 3, 7 };

            Assert.AreEqual(9, actual.Peek());
        }
开发者ID:robertrancz,项目名称:dsa,代码行数:6,代码来源:PriorityQueueTest.cs


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