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


C# Queue.Push方法代码示例

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


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

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

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

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

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

示例5: PopAndPush_LoopAndDoubleQueue

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

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

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

示例6: SendMsg

        private static async void SendMsg(Queue queue)
        {
            Task<string> getInput = GetInputAsync();
            // independent work which doesn't need the result of LongRunningOperationAsync can be done here

            //and now we call await on the task 
            string msg = await getInput;
            //use the result 
            queue.Push(GetLocalIPAddress() + ": " + msg);
        }
开发者ID:Novkirishki,项目名称:Web-Services-and-Cloud,代码行数:10,代码来源:Startup.cs

示例7: SendMessage

 private static void SendMessage(Queue queue)
 {
     while (Console.KeyAvailable)
     {
         ConsoleKeyInfo pressedKey = Console.ReadKey(true);
         if (pressedKey.Key == ConsoleKey.S)
         {
             Console.WriteLine("Please enter your message:");
             string outMsg = Console.ReadLine();
             queue.Push(String.Format("{0} : {1}", name, outMsg));
             Console.WriteLine("Message sent.");
         }
     }
 }
开发者ID:b-slavov,项目名称:Telerik-Software-Academy,代码行数:14,代码来源:Startup.cs

示例8: Push_5_Integers

        public void Push_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];
            queue.CopyTo(actual, 0);

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

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

示例10: Enumerate_5_Integers

        public void Enumerate_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 System.Collections.Generic.List<int>();

            foreach (var val in queue)
            {
                actual.Add(val);
            }

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

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

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

示例13: IsFull_FullQueue_True

 public void IsFull_FullQueue_True()
 {
     Queue<int> queue = new Queue<int>(1);
     queue.Push(1);
     Assert.AreEqual(true, queue.IsFull());
 }
开发者ID:Confirmit,项目名称:Students,代码行数:6,代码来源:QueueTests.cs

示例14: IsEmpty_1add_False

 public void IsEmpty_1add_False()
 {
     Queue<object> queue = new Queue<object>();
     queue.Push("string");
     Assert.AreEqual(false, queue.IsEmpty());
 }
开发者ID:Confirmit,项目名称:Students,代码行数:6,代码来源:QueueTests.cs

示例15: Push_OneMoreCapacityElements_SizeIsDoubled

        public void Push_OneMoreCapacityElements_SizeIsDoubled()
        {
            int capacity = 3;
            Queue<int> queue = new Queue<int>(capacity);
            int[] expectedQueue = new int[capacity + 1];

            for (int i = 0; i < capacity + 1; i++)
            {
                queue.Push(i);
                expectedQueue[i] = i;
            }

            Assert.AreEqual(capacity * 2, queue.Capacity, "Capacity is not doubled!");
            Assert.AreEqual(expectedQueue.Length, queue.Count, "Size is not right!");
            CollectionAssert.AreEqual(expectedQueue, queue.GetElements());
        }
开发者ID:Confirmit,项目名称:Students,代码行数:16,代码来源:QueueTests.cs


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