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


C# PriorityQueue.Dequeue方法代码示例

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


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

示例1: makeNextMove

        public int[] makeNextMove(Grid board)
        {
            PriorityQueue<MoveNode> q = new PriorityQueue<MoveNode>();
              	q.initialize(expandNodes(board, null, 1));
               	MoveNode current = q.Dequeue();

              	while ((current.Ply < depth) && !(q.isEmpty))
              	{
               		MoveNode next = q.Dequeue();
               	if(next.Rank> current.Rank)
               	{
                    current = next;
                    MoveNode[] expnd = expandNodes(current.Board, current, (current.Ply + 1));
                    if(expnd.Length > 0)
                        q.EnqueueArray(expnd);
                }
             	}

              	while(current.Ply > 1)
              	{
               		current = current.PreviousMove;
              	}
             	//this will be the best move to make after expanding down to depth plys.
              	int[] result = { current.Group.X, current.Group.Y };
              	Console.WriteLine("rank: " + current.Rank);

               	return result;
        }
开发者ID:TheProjecter,项目名称:netbreak,代码行数:28,代码来源:AI.cs

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

示例3: Remove

        public void Remove()
        {
            PriorityQueue<int> p = new PriorityQueue<int>(delegate(int i, int j) { return i - j; });
            Random r = new Random();
            for(int i = 0; i < 10000; ++i) {
                p.Enqueue(r.Next(1000));
            }

            int removed = 0;
            while(removed < 100) {
                int count = p.Count;
                p.Remove(r.Next(1000));
                if(count > p.Count) {
                    ++removed;
                }
            }

            int item = p.Dequeue();
            while(p.Count > 0) {
                int next = p.Dequeue();
                if(next < item) {
                    Assert.Fail("bad order detected");
                }
            }
        }
开发者ID:maximmass,项目名称:DReAM,代码行数:25,代码来源:PriorityQueueTests.cs

示例4: Main

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

            queue.Enqueue(5);
            queue.Enqueue(8);
            queue.Enqueue(3);
            queue.Enqueue(4);
            queue.Enqueue(11);

            foreach (var i in queue)
            {
                Console.WriteLine(i);
            }


            Console.WriteLine("*******Removed value:{0}",queue.Dequeue());
            foreach (var i in queue)
            {
                Console.WriteLine(i);
            }
            Console.WriteLine("*******Removed value:{0}", queue.Dequeue());
            foreach (var i in queue)
            {
                Console.WriteLine(i);
            }
        }
开发者ID:GenoGenov,项目名称:TelerikAcademyAssignments,代码行数:27,代码来源:Program.cs

示例5: Main

        public static void Main()
        {
            // 1.
            var priorityQueue = new PriorityQueue<int>();
            priorityQueue.Enqueue(2);
            priorityQueue.Enqueue(7);
            priorityQueue.Enqueue(17);
            priorityQueue.Enqueue(19);
            priorityQueue.Enqueue(26);
            priorityQueue.Enqueue(29);
            priorityQueue.Dequeue();
            priorityQueue.Enqueue(3);
            priorityQueue.Enqueue(1);
            priorityQueue.Dequeue();
            priorityQueue.Enqueue(25);
            priorityQueue.Enqueue(36);
            priorityQueue.Dequeue();

            Console.WriteLine();

            // 2.
            PrintFirst20Products();

            Console.WriteLine();

            // 3.
            CountWords();
        }
开发者ID:TeeeeeC,项目名称:TelerikAcademy2015-2016,代码行数:28,代码来源:Startup.cs

示例6: PriorityQueue

        public void PriorityQueue()
        {
            PriorityQueue<int> pq = new PriorityQueue<int>(LinqExt.TakeMore);
            pq.Enqueue(1, 1);
            pq.Enqueue(9, 9);
            pq.Enqueue(2, 2);
            pq.Enqueue(5, 5);

            Assert.IsTrue(pq.First() == 9, "Wrong Priority");
            Assert.IsTrue(pq.Dequeue() == 9, "Wrong Priority");
            Assert.IsTrue(pq.Dequeue() == 5, "Wrong Priority");

            pq.ChangePriority(1, 29);
            Assert.IsTrue(pq.First() == 1, "Wrong Priority, 1 should be first priority now with priority 29");

            pq.Enqueue(3, 2); //add item with same priority
            pq.Enqueue(4, 2); //add item with same priority

            Assert.IsTrue(pq.Last() == 4, "Wrong Priority, 4 should be last");

            pq.Enqueue(30, 30); // mix case
            Assert.IsTrue(pq.First() == 30, "Wrong Priority, 30 should be first priority");

            pq.Enqueue(31, 30); // mix case
            Assert.IsTrue(pq.First() == 30, "Wrong Priority, 30 should still be first priority");

            pq.Enqueue(5, 2); //add item with same priority
            pq.Enqueue(6, 2); //add item with same priority

            Assert.IsTrue(pq.Last() == 6, "Wrong Priority, 6 should be last");
        }
开发者ID:nantcom,项目名称:projecteuler,代码行数:31,代码来源:UtilityTest.cs

示例7: OnTick

        public async void OnTick(IWeiboAccessToken at)
        {
            if (_tick++%57 != 0)
                return;
            var resp = await WeiboClient.suggestions_statuses_hot_async(at.get(), 20, true, 1, _type);
            if(++_type == hot_status_type.count)
                _type = hot_status_type.musement;

            if (resp.Failed() || resp.Value.Length == 0)
                return;
            var queue = new PriorityQueue<long, Status>();
            foreach(var s in resp.Value)
            {
                queue.Enqueue(EvalMark(s),s);
            }
            while (queue.Size > 5)
                queue.Dequeue();
            while(!queue.IsEmpty)
            {
                var s = queue.Dequeue();
                var ws = new WeiboStatus();
                ws.assign_sina(s);
                await DispatcherHelper.UIDispatcher.BeginInvoke(DispatcherPriority.SystemIdle, (Action) (() =>
                {
                    if(statuses.Count > 10)
                        statuses.RemoveAt(0);
                    statuses.Add(ws);
                }));
            }
        }
开发者ID:heartszhang,项目名称:WeiZhi3,代码行数:30,代码来源:Recomendations.cs

示例8: EnqDeq

 public void EnqDeq()
 {
     var pq = new PriorityQueue<string>();
     pq.Enqueue(1, "world");
     pq.Enqueue(2, "hello");
     Assert.AreEqual("hello", pq.Dequeue());
     Assert.AreEqual("world", pq.Dequeue());
 }
开发者ID:nemerle,项目名称:reko,代码行数:8,代码来源:PriorityQueueTests.cs

示例9: ConstructFromSequence

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

示例10: TestOrder

        public void TestOrder()
        {
            PriorityQueue<int, string> q = new PriorityQueue<int, string>();
            q.Enqueue(0, "a");
            q.Enqueue(-1, "b");
            q.Enqueue(1, "c");

            Assert.AreEqual("b", q.Dequeue());
            Assert.AreEqual("a", q.Dequeue());
            Assert.AreEqual("c", q.Dequeue());

            q.Enqueue(0, "a");
            q.Enqueue(0, "b");
            q.Enqueue(0, "c");

            q.Enqueue(1, "c");
            q.Enqueue(1, "d");
            q.Enqueue(1, "e");

            Assert.AreEqual("a", q.Dequeue());
            Assert.AreEqual("b", q.Dequeue());
            Assert.AreEqual("c", q.Dequeue());

            Assert.AreEqual("c", q.Dequeue());
            Assert.AreEqual("d", q.Dequeue());
            Assert.AreEqual("e", q.Dequeue());
        }
开发者ID:anddudek,项目名称:anjlab.fx,代码行数:27,代码来源:PriorityQueueTests.cs

示例11: TestConstructWithComparer

        public void TestConstructWithComparer()
        {
            var q = new PriorityQueue<int>(Comparer<int>.Create((a, b) => -a.CompareTo(b)));

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

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

示例12: New_highest_prio_is_added_at_head

        public void New_highest_prio_is_added_at_head()
        {
            var sut = new PriorityQueue<string>();

            sut.Enqueue("0");
            sut.Enqueue(1, "1");
            sut.Enqueue(2, "2");

            Assert.AreEqual("2", sut.Dequeue());
            Assert.AreEqual("1", sut.Dequeue());
            Assert.AreEqual("0", sut.Dequeue());
        }
开发者ID:kennychou0529,项目名称:NPantaRhei,代码行数:12,代码来源:test_PriorityQueue.cs

示例13: BasicTest

 public void BasicTest()
 {
     var pq = new PriorityQueue<int>();
     pq.Enqueue(5);
     pq.Enqueue(3);
     pq.Enqueue(10);
     pq.Enqueue(1);
     Assert.AreEqual(1, pq.Dequeue());
     Assert.AreEqual(3, pq.Dequeue());
     Assert.AreEqual(5, pq.Dequeue());
     Assert.AreEqual(10, pq.Dequeue());
 }
开发者ID:sq,项目名称:Fracture,代码行数:12,代码来源:PriorityQueueTests.cs

示例14: CustomComparer

 public void CustomComparer()
 {
     var pq = new PriorityQueue<int>(
         (lhs, rhs) => (10 - lhs).CompareTo(10 - rhs)
     );
     pq.Enqueue(5);
     pq.Enqueue(3);
     pq.Enqueue(10);
     pq.Enqueue(1);
     Assert.AreEqual(10, pq.Dequeue());
     Assert.AreEqual(5, pq.Dequeue());
     Assert.AreEqual(3, pq.Dequeue());
     Assert.AreEqual(1, pq.Dequeue());
 }
开发者ID:sq,项目名称:Fracture,代码行数:14,代码来源:PriorityQueueTests.cs

示例15: Main

 static void Main(string[] args)
 {
     PriorityQueue<int> heap = new PriorityQueue<int>();
     heap.Enqueue(1);
     heap.Enqueue(2);
     heap.Enqueue(3);
     heap.Enqueue(4);
     heap.Dequeue();
     heap.Enqueue(3);
     heap.Enqueue(5);
     Console.WriteLine(heap.Dequeue());
     heap.ToString();
     heap.Enqueue(2);
     heap.ToString();
 }
开发者ID:damy90,项目名称:Telerik-all,代码行数:15,代码来源:Program.cs


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