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


C# PriorityQueue.Clear方法代码示例

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


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

示例1: Clear

        public void Clear()
        {
            var pq = new PriorityQueue<int>();

              pq.Clear();
              Assert.AreEqual(0, pq.Count);

              pq.Enqueue(777);
              pq.Enqueue(234);
              pq.Enqueue(13);

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

示例2: 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

示例3: 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

示例4: Simple

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

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

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

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

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

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

            var priorityQueue2 = new PriorityQueue<string, int>(PriorityQueueType.Minimum);

            priorityQueue2.Enqueue("a", 1);
            priorityQueue2.Enqueue("b", 2);
            priorityQueue2.Enqueue("c", 3);
            priorityQueue2.Enqueue("d", 4);
            priorityQueue2.Enqueue("e", 5);
            priorityQueue2.Enqueue("f", 6);

            priorityQueue2.Enqueue("z", 6);
            priorityQueue2.Enqueue("y", 5);
            priorityQueue2.Enqueue("x", 4);
            priorityQueue2.Enqueue("w", 3);
            priorityQueue2.Enqueue("v", 2);
            priorityQueue2.Enqueue("u", 1);

            priorityQueue2.Enqueue("z", 1);
            priorityQueue2.Enqueue("y", 2);
            priorityQueue2.Enqueue("x", 3);
            priorityQueue2.Enqueue("w", 4);
            priorityQueue2.Enqueue("v", 5);
            priorityQueue2.Enqueue("u", 6);

            Assert.AreEqual(priorityQueue2.Count, 18);

            priorityQueue2.Clear();

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

示例5: Main

        static void Main()
        {
            string decorationLine = new string('-', Console.WindowWidth);
            Console.Write(decorationLine);
            Console.WriteLine("***Presenting the functionality of the data structure 'Priority queue'***");
            Console.Write(decorationLine);

            PriorityQueue<int> numbers = new PriorityQueue<int>();

            Console.WriteLine("---Enqueue operation---");
            numbers.Enqueue(4);
            numbers.Enqueue(-1);
            numbers.Enqueue(3);
            numbers.Enqueue(22);
            numbers.Enqueue(16);
            numbers.Enqueue(-9);
            numbers.Enqueue(10);
            numbers.Enqueue(14);
            numbers.Enqueue(-48);
            numbers.Enqueue(71);
            Console.WriteLine("Count = " + numbers.Count);
            Console.WriteLine();

            Console.WriteLine("---Iterator functionality---");
            PrintNumbersOnConsole(numbers);
            Console.WriteLine();

            Console.WriteLine("---Peek operation---");
            int topNumber = numbers.Peek();
            Console.WriteLine("Count = " + numbers.Count);
            Console.WriteLine("The result from peek operation: " + topNumber);
            Console.WriteLine("Queue after peek:");
            PrintNumbersOnConsole(numbers);
            Console.WriteLine();

            Console.WriteLine("---Dequeue operation---");
            int poppedNumber = numbers.Dequeue();
            Console.WriteLine("The result from dequeue operation: " + poppedNumber);
            Console.WriteLine("Count = " + numbers.Count);
            Console.WriteLine("Queue after dequeue:");
            PrintNumbersOnConsole(numbers);
            Console.WriteLine();

            Console.WriteLine("---Clear operation---");
            numbers.Clear();
            Console.WriteLine("Elements count after clearing: " + numbers.Count);
        }
开发者ID:vladislav-karamfilov,项目名称:TelerikAcademy,代码行数:47,代码来源:PriorityQueueDemo.cs

示例6: Main

    static void Main()
    {
        var priQueue = new PriorityQueue<int>();

        priQueue.Add(-5);
        priQueue.Add(7);
        priQueue.Add(9);
        priQueue.Add(5);
        priQueue.Add(1);
        priQueue.Add(8);

        priQueue.Remove();

        foreach (var el in priQueue)
        {
            Console.WriteLine(el);
        }
        Console.WriteLine("Element count: {0}, Capacity: {1}", priQueue.Count, priQueue.Capacity);

        priQueue.Clear();
        Console.WriteLine("Element count: {0}, Capacity: {1}", priQueue.Count, priQueue.Capacity);
    }
开发者ID:nadiahristova,项目名称:Data-Structures-Algorithms-and-Complexity,代码行数:22,代码来源:ImplementBinaryHeap.cs

示例7: 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

示例8: Run

        public bool Run(Board board, Position blank_pos, Board goal_board, ref List<Move> moves, int grid_size, ref int boards_searched, ref int open_list_size, ref long timer, ref long memory_used)
        {
            hf_ = new HelperFunctions();

            if (hf_.CompareBoards(board, goal_board))
                return true;

            size_ = grid_size;

            AStarNode root = new AStarNode(board, null, blank_pos, null);
            AStarNode goal = new AStarNode(goal_board, null, null, null);

            PriorityQueue open_q = new PriorityQueue();
            HashSet<AStarNode> open_d = new HashSet<AStarNode>();
            HashSet<AStarNode> closed_list = new HashSet<AStarNode>();
            
            open_q.Add(root);
            open_d.Add(root);
            bool goal_found = false;

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            
            while(open_q.Size() > 0 && !goal_found) // && sw.ElapsedMilliseconds < 10000)
            {
                AStarNode next_node = open_q.GetNext();
                open_d.Remove(next_node);
                if (next_node.board_.Equals(goal.board_))
                {
                    timer = sw.ElapsedMilliseconds;
                    sw.Stop();
                    goal_found = true;
                    goal = next_node;
                    continue;
                }

                List<AStarNode> successors = GetChildren(next_node);

                foreach(AStarNode successor in successors)
                {
                    if (hf_.CompareBoards(successor, closed_list))
                        continue;

                    successor.g = next_node.g + 1;

                    if (hf_.CompareBoards(successor, open_d)) 
                        continue;

                    successor.h = ManhattanDistance(successor.board_);
                    successor.f = successor.g + successor.h;
                    open_q.Add(successor);
                    open_d.Add(successor);
                }

                closed_list.Add(next_node);
            }

            memory_used = GC.GetTotalMemory(false);
            open_list_size = open_q.Size();
            boards_searched = closed_list.Count;

            if(goal_found) TraverseTree(ref moves, goal);

            closed_list.Clear();
            open_d.Clear();
            open_q.Clear();
            GC.Collect();

            return goal_found;
        }
开发者ID:djquirke,项目名称:AIPersonal,代码行数:71,代码来源:AI_AStar.cs

示例9: ClearExample

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

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

            // Clear the priorityQueue
            priorityQueue.Clear();

            // The priorityQueue should be empty.
            Assert.AreEqual(0, priorityQueue.Count);

            // No cat here..
            Assert.IsFalse(priorityQueue.Contains("cat"));
        }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:19,代码来源:PriorityQueueExamples.cs

示例10: Count

        public void Count()
        {
            var pq = new PriorityQueue<int>();
              Assert.AreEqual(0, pq.Count);

              pq.Enqueue(123);
              Assert.AreEqual(1, pq.Count);

              pq.Enqueue(31);
              pq.Enqueue(64);
              Assert.AreEqual(3, pq.Count);

              for (int i = 0; i < 30; i++)
            pq.Enqueue(i);

              pq.Peek();
              pq.Dequeue();
              pq.Dequeue();
              Assert.AreEqual(31, pq.Count);

              pq.Clear();
              Assert.AreEqual(0, pq.Count);
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:23,代码来源:PriorityQueueTest.cs

示例11: Enumerator

        public void Enumerator()
        {
            var pq = new PriorityQueue<int>();

              for (int i = 0; i < 10; i++)
            pq.Enqueue(i);

              var list = new List<int>();
              foreach (var i in pq)
              {
            Assert.IsTrue(!list.Contains(i));
            list.Add(i);
              }

              Assert.AreEqual(pq.Count, list.Count);

              Assert.Throws(typeof(InvalidOperationException), () =>
              {
            foreach (var i in pq)
            {
              pq.Enqueue(1);
            }
              });

              Assert.Throws(typeof(InvalidOperationException), () =>
              {
            foreach (var i in pq)
            {
              pq.Dequeue();
            }
              });

              Assert.Throws(typeof(InvalidOperationException), () =>
              {
            foreach (var i in pq)
            {
              pq.Remove(1);
            }
              });

              Assert.Throws(typeof(InvalidOperationException), () =>
              {
            foreach (var i in pq)
            {
              pq.Clear();
            }
              });
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:48,代码来源:PriorityQueueTest.cs


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