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


C# Queue.Pop方法代码示例

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


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

示例1: DoTest

		public static void DoTest ()
		{
			string top;
			Queue<string> queue = new Queue<string>();

			queue.Enqueue("aaa");
			queue.Enqueue("bbb");
			queue.Enqueue("ccc");
			queue.Enqueue("ddd");
			queue.Enqueue("eee");
			queue.Enqueue("fff");
			queue.Enqueue("ggg");
			queue.Enqueue("hhh");

			Console.WriteLine("Queue Elements:\r\n" + queue.ToHumanReadable());

			var array = queue.ToArray();
			Debug.Assert (array.Length == 8, "Wrong size.");

			queue.Pop();
			queue.Pop();
			top = queue.Dequeue();

			Console.WriteLine("Old 3nd-last: " + top + "\r\n");
			Console.WriteLine("Queue Elements:\r\n" + queue.ToHumanReadable());

			queue.Pop();
			queue.Pop();

			Console.WriteLine("Queue Elements:\r\n" + queue.ToHumanReadable());

			var array2 = queue.ToArray();
			Debug.Assert (array2.Length == 3, "Wrong size.");
		}
开发者ID:hjorturls,项目名称:C-Sharp-Algorithms,代码行数:34,代码来源:QueueTest.cs

示例2: CountTest

        public void CountTest()
        {
            var queue = new Queue<int>();
            queue.Push(1);
            queue.Push(2);

            Assert.That(queue.Count, Is.EqualTo(2));
            queue.Pop();
            queue.Pop();
            Assert.That(queue.Count, Is.EqualTo(0));
        }
开发者ID:osst,项目名称:University,代码行数:11,代码来源:Tests.cs

示例3: FrontTest

        public void FrontTest()
        {
            var queue = new Queue<int>();
            queue.Push(1);
            queue.Push(2);

            Assert.That(queue.Front, Is.EqualTo(1));
            queue.Pop();
            Assert.That(queue.Front, Is.EqualTo(2));
            queue.Pop();

            Assert.Throws<InvalidOperationException>(delegate { int a = queue.Front; });
        }
开发者ID:osst,项目名称:University,代码行数:13,代码来源:Tests.cs

示例4: PopAndPush_LoopQueue

        public void PopAndPush_LoopQueue()
        {
            int capacity = 3;
            Queue<int> queue = new Queue<int>(capacity);
            int[] expectedQueue = { 1, 4, 5 };

            queue.Push(3);
            queue.Push(2);
            queue.Push(1);
            queue.Pop();
            queue.Push(4);
            queue.Pop();
            queue.Push(5);

            Assert.AreEqual(capacity, queue.Capacity, "Capacity is increased!");
            CollectionAssert.AreEqual(expectedQueue, queue.GetElements());
        }
开发者ID:Confirmit,项目名称:Students,代码行数:17,代码来源:QueueTests.cs

示例5: QueueTest

        static void QueueTest()
        {
            Queue<int> q = new Queue<int>();

            q.Push(1);
            q.Push(2);
            q.Push(3);
            q.Push(4);

            while (q.Length > 0)
            {
                Console.WriteLine(q.Pop());
            }
        }
开发者ID:IrenaBu,项目名称:PredavanjaNET,代码行数:14,代码来源:Program.cs

示例6: Pop_5_Integers

        public void Pop_5_Integers()
        {
            var expected = new int[] { 0, 1, 2, 3, 4 };
            Queue<int> queue = new Queue<int>();

            for (var i = 0; i < 5; i++)
            {
                queue.Push(i);
            }

            var actual = new int[5];
            for (var i = 0; i < 5; i++)
            {
                actual[i] = queue.Pop();
            }

            CollectionAssert.AreEqual(expected, actual);
        }
开发者ID:EBrown8534,项目名称:Framework,代码行数:18,代码来源:QueueTests.cs

示例7: Main

 public static int Main()
 {
     string cmd;
     int val;
     Queue<int> q = new Queue<int>();
     while (true)
     {
         Console.WriteLine();
         Console.WriteLine("Commands: push, pop, front, length, print, exit");
         Console.Write("? ");
         cmd = Console.ReadLine();
         try
         {
             if (cmd == "push")
             {
                 Console.Write("Value: ");
                 val = Int32.Parse(Console.ReadLine());
                 q.Push(val);
             }
             else if (cmd == "pop")
             {
                 q.Pop();
                 Console.WriteLine("first element is deleted");
             }
             else if (cmd == "front")
                 Console.WriteLine(q.Front());
             else if (cmd == "length")
                 Console.WriteLine(q.Length);
             else if (cmd == "exit")
                 break;
             else if (cmd == "print")
                 q.Print();
             else
                 Console.WriteLine("Incorrect command");
         }
         catch (EmptyQueue)
         {
             Console.WriteLine("Empty queue");
         }
         Console.WriteLine();
     }
     return 0;
 }
开发者ID:Ozerich,项目名称:labs,代码行数:43,代码来源:Main.cs

示例8: ShortestPath

        public static int ShortestPath(Vertex start, Vertex end)
        {
            Queue<Vertex> queue = new Queue<Vertex>(10);

            if (start == null || end == null)
                return 0;

            start.Status = Color.Grey;
            queue.Push(start);

            Vertex cur = null;
            while (!queue.IsEmpty())
            {
                cur = queue.Pop();
                if (cur == end)
                {
                    break;
                }

                foreach (Vertex v in cur.Neighbors)
                {
                    if (v.Status == Color.White)
                    {
                        v.Status = Color.Grey;
                        v.Parent = cur;
                        v.Distance = cur.Distance + 1;
                        queue.Push(v);
                    }
                }

                cur.Status = Color.Black;
            }

            if (cur.Parent == null)
                return 0;
            else
                return cur.Parent.Distance + 1;
        }
开发者ID:yizhengc,项目名称:MyAlgorithmCode,代码行数:38,代码来源:Graph.cs

示例9: Pop_NoElements_Exception

 public void Pop_NoElements_Exception()
 {
     Queue<int> queue = new Queue<int>();
     queue.Pop();
 }
开发者ID:Confirmit,项目名称:Students,代码行数:5,代码来源:QueueTests.cs

示例10: Pop_3214elements_3returned

        public void Pop_3214elements_3returned()
        {
            Queue<int> queue = new Queue<int>();
            queue.Push(3);
            queue.Push(2);
            queue.Push(1);
            queue.Push(4);
            int[] expectedQueue = {2, 1, 4};

            int actualNumber = queue.Pop();

            Assert.AreEqual(3, actualNumber);
            CollectionAssert.AreEqual(expectedQueue, queue.GetElements());
        }
开发者ID:Confirmit,项目名称:Students,代码行数:14,代码来源:QueueTests.cs


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