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


C# LinkedQueue.Enqueue方法代码示例

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


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

示例1: Main

        static void Main()
        {
            LinkedQueue<int> linkedQueue = new LinkedQueue<int>();

            LinkedQueue<string> anotherLinkedQueue = new LinkedQueue<string>(
                new List<string> { "pesho", "gosho", "sasho", "misho" });

            Console.WriteLine(anotherLinkedQueue);
            Console.WriteLine("First: " + anotherLinkedQueue.First.Value);
            Console.WriteLine("Last: " + anotherLinkedQueue.Last.Value);
            Console.WriteLine();

            linkedQueue.Enqueue(15);
            linkedQueue.Enqueue(20);
            Console.WriteLine(linkedQueue);

            linkedQueue.Enqueue(50);
            linkedQueue.Enqueue(100);
            Console.WriteLine(linkedQueue);

            anotherLinkedQueue.Dequeue();
            Console.WriteLine(anotherLinkedQueue);

            linkedQueue.Dequeue();
            Console.WriteLine(linkedQueue);

            Console.WriteLine(linkedQueue.Peek());

            anotherLinkedQueue.Clear();
            Console.WriteLine(anotherLinkedQueue.Count == 0 && anotherLinkedQueue.First == null && anotherLinkedQueue.Last == null);
        }
开发者ID:smihaylovit,项目名称:DSA,代码行数:31,代码来源:LinkedQueueMain.cs

示例2: Main

        static void Main()
        {
            try
            {
                LinkedQueue<string> queue = new LinkedQueue<string>();
                queue.Enqueue("Message One");
                queue.Enqueue("Message Two");
                queue.Enqueue("Message Three");
                queue.Enqueue("Message Four");

                Console.WriteLine(queue.Peek());
                Console.WriteLine(queue.Contains("Message Three"));

                var array = queue.ToArray();
                Console.WriteLine(string.Join(", ", array));

                while (queue.Count > 0)
                {
                    string message = queue.Dequeue();
                    Console.WriteLine(message);
                }

                queue.Dequeue();
            }
            catch (IndexOutOfRangeException iex)
            {
                Console.WriteLine(iex.TargetSite + " -> " + iex.Message);
            }
            catch (NullReferenceException nex)
            {
                Console.WriteLine(nex.TargetSite + " -> " + nex.Message);
            }
        }
开发者ID:niki-funky,项目名称:Telerik_Academy,代码行数:33,代码来源:Demo.cs

示例3: TestLinkedQueue

        private static void TestLinkedQueue()
        {
            ILinkedQueue<int> linkedQueue = new LinkedQueue<int>();

            // Should return true
            var isEmpty = linkedQueue.IsEmpty();

            linkedQueue.Enqueue(1);
            linkedQueue.Enqueue(2);
            linkedQueue.Enqueue(3);
            linkedQueue.Enqueue(4);
            // Should have 4 elements

            // Should remove first added element - (1) and return it
            var removedElement = linkedQueue.Dequeue();

            // Should return first element - (2)
            var firstElement = linkedQueue.Peek();

            // Should return 3
            var count = linkedQueue.Count;

            // Should return false
            isEmpty = linkedQueue.IsEmpty();
        }
开发者ID:Nikolay-D,项目名称:DataStructuresAndAlgorithms,代码行数:25,代码来源:Startup.cs

示例4: Push_Pop_Two

        public void Push_Pop_Two()
        {
            var ints = new LinkedQueue<int> ();
            Assert.AreEqual (0, ints.Count);

            int element1 = 1;
            ints.Enqueue (element1);
            Assert.AreEqual (1, ints.Count);

            int element2 = 2;
            ints.Enqueue (element2);
            Assert.AreEqual (2, ints.Count);

            {
                int poppedEl = ints.Dequeue ();
                Assert.AreEqual (poppedEl, element1);
                Assert.AreEqual (1, ints.Count);
            }

            {
                int poppedEl = ints.Dequeue ();
                Assert.AreEqual (poppedEl, element2);
                Assert.AreEqual (0, ints.Count);
            }
        }
开发者ID:psha-,项目名称:softuni-datastruct,代码行数:25,代码来源:UnitTestsLinkedQueue.cs

示例5: EnqueueAndDequeueSeveralElements1ShouldWorkCorrectly

        public void EnqueueAndDequeueSeveralElements1ShouldWorkCorrectly()
        {
            //Arrange
            var queue = new LinkedQueue<int>();
            //Assert
            Assert.AreEqual(0, queue.Count);

            //Act
            queue.Enqueue(5);
            //Assert
            Assert.AreEqual(1, queue.Count);
            //Act
            queue.Enqueue(6);
            //Assert
            Assert.AreEqual(2, queue.Count);
            //Act
            var element = queue.Dequeue();
            //Assert
            Assert.AreEqual(5, element);
            Assert.AreEqual(1, queue.Count);
            //Act
            element = queue.Dequeue();
            //Assert
            Assert.AreEqual(6, element);
            Assert.AreEqual(0, queue.Count);
        }
开发者ID:anichalakova,项目名称:DataStructuresHWs,代码行数:26,代码来源:UnitTestsLinkedQueue.cs

示例6: Main

 static void Main()
 {
     // TODO: Epxlain the tests
     Console.WriteLine("Testing custom queue class.");
     Console.WriteLine("Class features:");
     Console.WriteLine(" - linked list implementation");
     Console.WriteLine(" - methods Enqueue, Dequeue, Peek, Contains and property Count.");
     Console.WriteLine();
     Console.WriteLine("Creating a LinkedQueue.");
     LinkedQueue<int> queue = new LinkedQueue<int>();
     Console.WriteLine("DONE!" + Environment.NewLine);
     Console.WriteLine("Enqueuing numbers from 1 to 10");
     for (int i = 1; i <= 10; i++)
     {
         queue.Enqueue(i);
     }
     Console.WriteLine("DONE!" + Environment.NewLine);
     Console.WriteLine("Printing queue using custom enumerator:");
     Print(queue);
     Console.WriteLine("Peeking: " + queue.Peek());
     Console.WriteLine();
     Console.WriteLine("Dequeuing 7 elements");
     for (int i = 0; i < 7; i++)
     {
         queue.Dequeue();
     }
     Console.Write("Press any key to continue testing.");
     Console.ReadKey();
     Console.WriteLine();
     Console.WriteLine("Printing queue:");
     Print(queue);
     Console.WriteLine("Enqueuing numbers from 1 to 10");
     for (int i = 1; i <= 10; i++)
     {
         queue.Enqueue(i);
     }
     Console.WriteLine("Peeking: " + queue.Peek());
     Console.WriteLine();
     Console.WriteLine("Printing queue:");
     Print(queue);
     Console.WriteLine("Cheking if queue contains the number 5: " + queue.Contains(5));
     Console.WriteLine("Cheking if queue contains the number -15: " + queue.Contains(-15));
     Console.WriteLine();
     Console.WriteLine("Clearing the queue");
     queue.Clear();
     Console.WriteLine("Cleared");
     Console.WriteLine();
     Console.WriteLine("Printing queue:");
     Print(queue);
     try
     {
         Console.WriteLine("Peeking: ");
         queue.Peek();
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
 }
开发者ID:klimentt,项目名称:Telerik-Academy,代码行数:59,代码来源:TestProgram.cs

示例7: Main

 static void Main()
 {
     LinkedQueue<int> myQueue = new LinkedQueue<int>();
     myQueue.Enqueue(5);
     myQueue.Enqueue(6);
     Console.WriteLine(myQueue.Dequeue());
     Console.WriteLine(myQueue.Dequeue());
 }
开发者ID:zvet80,项目名称:TelerikAcademyHomework,代码行数:8,代码来源:Program.cs

示例8: TestCountAfterEnqueue

 public void TestCountAfterEnqueue()
 {
     var queue = new LinkedQueue<int>();
     queue.Enqueue(1);
     queue.Enqueue(2);
     queue.Enqueue(3);
     Assert.AreEqual(3, queue.Count);
 }
开发者ID:bobosam,项目名称:DataStructures,代码行数:8,代码来源:LinkedQueueTests.cs

示例9: Main

        public static void Main()
        {
            LinkedQueue<int> sue = new LinkedQueue<int>();
            sue.Enqueue(5);
            sue.Enqueue(1);
            sue.Enqueue(7);

            sue.Dequeue();
        }
开发者ID:RamiAmaire,项目名称:TelerikAcademy,代码行数:9,代码来源:Demo.cs

示例10: Main

 static void Main(string[] args)
 {
     var linkedQueue = new LinkedQueue<int>();
     linkedQueue.Dequeue();
     linkedQueue.Enqueue(5);
     linkedQueue.Enqueue(6);
     linkedQueue.Enqueue(7);
     Console.WriteLine(string.Join(" ",linkedQueue.ToArray()));
 }
开发者ID:anichalakova,项目名称:DataStructuresHWs,代码行数:9,代码来源:Program.cs

示例11: Dequeue_ShouldDecrementCount

        public void Dequeue_ShouldDecrementCount()
        {
            var queue = new LinkedQueue<int>();
            queue.Enqueue(5);
            queue.Enqueue(7);
            queue.Dequeue();

            Assert.AreEqual(1, queue.Count, "Dequeue isn't working correctly.");
        }
开发者ID:broxigarthered,项目名称:HQC-Homeworks-Softuni,代码行数:9,代码来源:LinkedQueueTests.cs

示例12: TestCount_SingleElement_CountOne

        public void TestCount_SingleElement_CountOne()
        {
            var queue = new LinkedQueue<int>();
            queue.Enqueue(50);
            queue.Enqueue(60);
            queue.Enqueue(70);
            queue.Enqueue(int.MaxValue);

            Assert.AreEqual(4, queue.Count, "Queue count should be 4.");
        }
开发者ID:eslavov11,项目名称:SoftUni-Homework,代码行数:10,代码来源:LinkedQueueTests.cs

示例13: DequeueElementFromLinkedStackShouldReturnTheLastElement

        public void DequeueElementFromLinkedStackShouldReturnTheLastElement()
        {
            LinkedQueue<int> arrayStack = new LinkedQueue<int>();
            arrayStack.Enqueue(1);
            arrayStack.Enqueue(2);
            arrayStack.Enqueue(3);
            var lastElement = arrayStack.Dequeue();

            Assert.AreEqual(3, lastElement);
        }
开发者ID:rozay,项目名称:Data-Structures,代码行数:10,代码来源:LinkedQueueTests.cs

示例14: To_Array

 public void To_Array()
 {
     var nums = new LinkedQueue<int>();
     nums.Enqueue(3);
     nums.Enqueue(5);
     nums.Enqueue(-2);
     nums.Enqueue(7);
     int[] arrTest = { 3, 5, -2, 7 };
     CollectionAssert.AreEqual(arrTest, nums.ToArray());
 }
开发者ID:asenAce,项目名称:Software_University_Bulgaria,代码行数:10,代码来源:LinkedQueueTest.cs

示例15: DequeueTest_CheckTheExpectedCount

        public void DequeueTest_CheckTheExpectedCount()
        {
            LinkedQueue<int> queue = new LinkedQueue<int>();

            queue.Enqueue(45);
            queue.Enqueue(32);
            queue.Enqueue(1);

            Assert.AreEqual(3, queue.Count, "Count is not the same as expected after the Enqueue");
        }
开发者ID:zhecho1215,项目名称:Softuni,代码行数:10,代码来源:LinkedQueueTests.cs


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