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


C# PriorityQueue.Add方法代码示例

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


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

示例1: Simple

        public void Simple()
        {
            var priorityQueue = new PriorityQueue<string, int>(PriorityQueueType.Minimum) { "5" };

            Assert.AreEqual(priorityQueue.Count, 1);
            Assert.IsTrue(priorityQueue.Contains("5"));
            Assert.IsTrue(priorityQueue.Remove("5"));
            Assert.AreEqual(priorityQueue.Count, 0);

            priorityQueue.Add("6");
            priorityQueue.Add("7");
            priorityQueue.Add("2", 4);

            Assert.AreEqual(priorityQueue.Count, 3);
            Assert.IsTrue(priorityQueue.Contains("6"));
            Assert.IsTrue(priorityQueue.Contains("7"));
            Assert.IsTrue(priorityQueue.Contains("2"));

            Assert.IsFalse(priorityQueue.Remove("8"));

            Assert.IsTrue(priorityQueue.Remove("7"));
            Assert.AreEqual(priorityQueue.Count, 2);
            Assert.IsTrue(priorityQueue.Remove("2"));
            Assert.AreEqual(priorityQueue.Count, 1);
            Assert.IsTrue(priorityQueue.Remove("6"));
            Assert.AreEqual(priorityQueue.Count, 0);

            Assert.IsFalse(priorityQueue.Remove("7"));
        }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:29,代码来源:Remove.cs

示例2: RandomTest

 public void RandomTest()
 {
     PriorityQueue<int> TestObject = new PriorityQueue<int>();
     Utilities.Random.Random Rand = new Utilities.Random.Random();
     int Value=0;
     for (int x = 0; x < 10; ++x)
     {
         Value=Rand.Next();
         TestObject.Add(x, Value);
         Assert.Equal(Value, TestObject.Peek());
     }
     int HighestValue = TestObject.Peek();
     for (int x = 9; x >= 0; --x)
     {
         Value = Rand.Next();
         TestObject.Add(x, Value);
         Assert.Equal(HighestValue, TestObject.Peek());
     }
     int Count=0;
     foreach(int Priority in TestObject.Keys)
     {
         foreach(int Item in TestObject[Priority])
         {
             ++Count;
         }
     }
     Assert.Equal(20, Count);
 }
开发者ID:gwilkinson,项目名称:Craig-s-Utility-Library,代码行数:28,代码来源:PriorityQueue.cs

示例3: AddExample

        public void AddExample()
        {
            var priorityQueue = new PriorityQueue<string, int>(PriorityQueueType.Minimum);
            priorityQueue.Add("cat");
            priorityQueue.Add("dog");
            priorityQueue.Add("canary");

            // There will be 3 items in the priorityQueue.
            Assert.AreEqual(3, priorityQueue.Count);
        }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:10,代码来源:PriorityQueueExamples.cs

示例4: AddPriorityExample

        public void AddPriorityExample()
        {
            var priorityQueue = new PriorityQueue<string, int>(PriorityQueueType.Minimum);
            priorityQueue.Add("cat", 2);
            priorityQueue.Add("canary", 1);
            priorityQueue.Add("dog", 3);

            // There will be 3 items in the priorityQueue.
            Assert.AreEqual(3, priorityQueue.Count);

            // "canary" will be at the top as it has the highest priority
            Assert.AreEqual("canary", priorityQueue.Peek());
        }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:13,代码来源:PriorityQueueExamples.cs

示例5: Simple

        public void Simple()
        {
            var priorityQueue = new PriorityQueue<int, int>(PriorityQueueType.Maximum);
            Assert.IsFalse(priorityQueue.IsReadOnly);

            priorityQueue.Add(4);
            Assert.IsFalse(priorityQueue.IsReadOnly);

            priorityQueue.Add(99);
            Assert.IsFalse(priorityQueue.IsReadOnly);

            priorityQueue.Clear();
            Assert.IsFalse(priorityQueue.IsReadOnly);
        }
开发者ID:havok,项目名称:ngenerics,代码行数:14,代码来源:IsReadOnly.cs

示例6: Simple

        public void Simple()
        {
            var priorityQueue = new PriorityQueue<int, int>(PriorityQueueType.Minimum);
            Assert.AreEqual(priorityQueue.Count, 0);

            priorityQueue.Add(4);
            Assert.AreEqual(priorityQueue.Count, 1);

            priorityQueue.Add(99);
            Assert.AreEqual(priorityQueue.Count, 2);

            priorityQueue.Clear();
            Assert.AreEqual(priorityQueue.Count, 0);
        }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:14,代码来源:Count.cs

示例7: Main

        public static void Main(string[] args)
        {
            var priorityQueue = new PriorityQueue<int>();

            priorityQueue.Add(1);
            priorityQueue.Add(2);
            priorityQueue.Add(513);
            priorityQueue.Add(51);
            priorityQueue.Add(1551);

            while (priorityQueue.Count > 0)
            {
                Console.WriteLine(priorityQueue.Dequeue());
            }
        }
开发者ID:ni4ka7a,项目名称:TelerikAcademyHomeworks,代码行数:15,代码来源:Startup.cs

示例8: Main

    /* Task 1:  
     * Implement a class PriorityQueue<T> based on the data structure "binary heap".
     */

    static void Main(string[] args)
    {
        var prioQueue = new PriorityQueue<int>();

        prioQueue.Add(25);
        prioQueue.Add(15);
        prioQueue.Add(105);
        prioQueue.Add(5);
        prioQueue.Add(35);

        Console.WriteLine(prioQueue.Count());
        Console.WriteLine(prioQueue.Dequeue());
        Console.WriteLine(prioQueue.Dequeue());
        Console.WriteLine(prioQueue.Dequeue());
        Console.WriteLine(prioQueue.Dequeue());
    }
开发者ID:aleks-todorov,项目名称:HomeWorks,代码行数:20,代码来源:Program.cs

示例9: PriorityQueueGeneralTest

        public void PriorityQueueGeneralTest()
        {
            var queue = new PriorityQueue<int>();

            Assert.IsTrue(queue.Empty, "New queue should start out empty.");
            Assert.Throws<InvalidOperationException>(() => queue.Peek(), "Peeking at an empty queue should throw.");
            Assert.Throws<InvalidOperationException>(() => queue.Pop(), "Popping an empty queue should throw.");

            foreach (var value in new[] { 4, 3, 5, 1, 2 })
            {
                queue.Add(value);
                Assert.IsFalse(queue.Empty, "Queue should not be empty - items have been added.");
            }

            foreach (var value in new[] { 1, 2, 3, 4, 5 })
            {
                Assert.AreEqual(value, queue.Peek(), "Peek returned the wrong item - should be in order.");
                Assert.IsFalse(queue.Empty, "Queue should not be empty yet.");
                Assert.AreEqual(value, queue.Pop(), "Pop returned the wrong item - should be in order.");
            }

            Assert.IsTrue(queue.Empty, "Queue should now be empty.");
            Assert.Throws<InvalidOperationException>(() => queue.Peek(), "Peeking at an empty queue should throw.");
            Assert.Throws<InvalidOperationException>(() => queue.Pop(), "Popping an empty queue should throw.");
        }
开发者ID:CH4Code,项目名称:OpenRA,代码行数:25,代码来源:PriorityQueueTest.cs

示例10: Simple

        public void Simple()
        {
            var priorityQueue1 = new PriorityQueue<int, int>(PriorityQueueType.Minimum) { 4 };

            Assert.AreEqual(priorityQueue1.Count, 1);
            Assert.AreEqual(priorityQueue1.Dequeue(), 4);

            priorityQueue1.Add(5);
            priorityQueue1.Add(6, 2);

            Assert.AreEqual(priorityQueue1.Dequeue(), 5);
            Assert.AreEqual(priorityQueue1.Dequeue(), 6);

            priorityQueue1.Add(6, 2);
            priorityQueue1.Add(5);

            Assert.AreEqual(priorityQueue1.Dequeue(), 5);
            Assert.AreEqual(priorityQueue1.Dequeue(), 6);

            var priorityQueue2 = new PriorityQueue<string, int>(PriorityQueueType.Minimum)
                                     {
                                         {"a", 1},
                                         {"b", 2},
                                         {"c", 3},
                                         {"d", 4},
                                         {"e", 5},
                                         {"f", 6},
                                         {"z", 6},
                                         {"y", 5},
                                         {"x", 4},
                                         {"w", 3},
                                         {"v", 2},
                                         {"u", 1},
                                         {"z", 1},
                                         {"y", 2},
                                         {"x", 3},
                                         {"w", 4},
                                         {"v", 5},
                                         {"u", 6}
                                     };

            Assert.AreEqual(priorityQueue2.Count, 18);

            priorityQueue2.Clear();

            Assert.AreEqual(priorityQueue2.Count, 0);
        }
开发者ID:havok,项目名称:ngenerics,代码行数:47,代码来源:Add.cs

示例11: Main

        private static void Main()
        {
            var priorityQueue = new PriorityQueue<int>();
            priorityQueue.Add(1);
            priorityQueue.Add(1);
            priorityQueue.Add(3);
            priorityQueue.Add(1);
            priorityQueue.Add(3);
            priorityQueue.Add(10);
            priorityQueue.Add(2);
            priorityQueue.Add(2);
            priorityQueue.Add(3);
            priorityQueue.Add(2);

            while (priorityQueue.Count != 0)
            {
                Console.WriteLine(priorityQueue.Dequeue());
            }
        }
开发者ID:VladimirDimov,项目名称:DSA,代码行数:19,代码来源:Startup.cs

示例12: WithPriority

        public void WithPriority()
        {
            var priorityQueue = new PriorityQueue<string, int>(PriorityQueueType.Minimum);

            int priority;

            priorityQueue.Add("5", 3);
            Assert.AreEqual(priorityQueue.Count, 1);
            Assert.IsTrue(priorityQueue.Contains("5"));
            Assert.IsTrue(priorityQueue.Remove("5", out priority));
            Assert.AreEqual(priority, 3);

            Assert.AreEqual(priorityQueue.Count, 0);

            priorityQueue.Add("6");
            priorityQueue.Add("7");
            priorityQueue.Add("2", 4);

            Assert.AreEqual(priorityQueue.Count, 3);
            Assert.IsTrue(priorityQueue.Contains("6"));
            Assert.IsTrue(priorityQueue.Contains("7"));
            Assert.IsTrue(priorityQueue.Contains("2"));

            Assert.IsFalse(priorityQueue.Remove("8", out priority));

            Assert.IsTrue(priorityQueue.Remove("7", out priority));
            Assert.AreEqual(priority, 0);
            Assert.AreEqual(priorityQueue.Count, 2);

            Assert.IsTrue(priorityQueue.Remove("2", out priority));
            Assert.AreEqual(priority, 4);

            Assert.AreEqual(priorityQueue.Count, 1);
            Assert.IsTrue(priorityQueue.Remove("6", out priority));
            Assert.AreEqual(priority, 0);
            Assert.AreEqual(priorityQueue.Count, 0);

            Assert.IsFalse(priorityQueue.Remove("7", out priority));
        }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:39,代码来源:Remove.cs

示例13: TestPriorityQueueCount

 public void TestPriorityQueueCount()
 {
     PriorityQueue<int> pq = new PriorityQueue<int>();
     pq.Add(5);
     pq.Add(6);
     pq.Add(3);
     pq.Add(7);
     pq.Add(11);
     pq.Add(-5);
     pq.GetTop();
     pq.GetTop();
     Assert.AreEqual(4, pq.Count, "Incorrectly counting the queue elements");
 }
开发者ID:ilkodzhambazov,项目名称:Telerik-Academy,代码行数:13,代码来源:PriorityQueueTests.cs

示例14: TestPriorityQueueOrder_2

 public void TestPriorityQueueOrder_2()
 {
     PriorityQueue<int> pq = new PriorityQueue<int>();
     pq.Add(5);
     pq.Add(6);
     pq.Add(3);
     pq.Add(7);
     Assert.AreEqual(3, pq.GetTop(), "Incorrect element returned!");
     pq.Add(11);
     pq.Add(-5);
     Assert.AreEqual(-5, pq.GetTop(), "Incorrect element returned!");
     pq.Add(6);
     Assert.AreEqual(5, pq.GetTop(), "Incorrect element returned!");
     Assert.AreEqual(6, pq.GetTop(), "Incorrect element returned!");
     Assert.AreEqual(6, pq.GetTop(), "Incorrect element returned!");
     Assert.AreEqual(7, pq.GetTop(), "Incorrect element returned!");
     Assert.AreEqual(11, pq.GetTop(), "Incorrect element returned!");
 }
开发者ID:ilkodzhambazov,项目名称:Telerik-Academy,代码行数:18,代码来源:PriorityQueueTests.cs

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