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


C# LinkedQueue.Peek方法代码示例

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


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

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

示例2: Main

 static void Main()
 {
     var test = new LinkedQueue<int>();
     test.Enqueue(1);
     Console.WriteLine(string.Join(" ", test.ToArray()));
     test.Enqueue(2);
     Console.WriteLine(string.Join(" ", test.ToArray()));
     test.Enqueue(3);
     Console.WriteLine(string.Join(" ", test.ToArray()));
     test.Enqueue(4);
     Console.WriteLine(string.Join(" ", test.ToArray()));
     test.Enqueue(5);
     Console.WriteLine(string.Join(" ", test.ToArray()));
     test.Enqueue(6);
     Console.WriteLine(string.Join(" ", test.ToArray()));
     test.Enqueue(7);
     Console.WriteLine(string.Join(" ", test.ToArray()));
     Console.WriteLine("The queue count: {0}", test.Count);
     test.Dequeue();
     test.Dequeue();
     Console.WriteLine(string.Join(" ", test.ToArray()));
     Console.WriteLine("The queue count: {0}", test.Count);
     Console.WriteLine(test.Peek());
     Console.WriteLine(string.Join(" ", test.ToArray()));
     Console.WriteLine("The queue count: {0}", test.Count);
     test.Clear();
     Console.WriteLine(string.Join(" ", test.ToArray()));
     Console.WriteLine("The queue count: {0}", test.Count);
     //test.Dequeue();                           //if uncommented this line should throw exception
 }
开发者ID:kalinalazarova1,项目名称:TelerikAcademy,代码行数:30,代码来源:LinkedQueueTest.cs

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

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

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

示例6: Main

 static void Main()
 {
     var lq = new LinkedQueue<int>();
     lq.Enqueue(5);
     lq.Enqueue(11);
     lq.Enqueue(22);
     lq.Enqueue(33);
     lq.Enqueue(44);
     lq.Dequeue();
     var p = lq.Peek();
     lq.Enqueue(55);
     lq.Enqueue(11);
     lq.Enqueue(22);
     lq.Enqueue(33);
     lq.Enqueue(44);
     lq.Dequeue();
     lq.Enqueue(55);
     lq.Enqueue(11);
     lq.Enqueue(22);
     lq.Enqueue(33);
     lq.Enqueue(44);
     lq.Dequeue();
     lq.Enqueue(55);
     lq.Enqueue(11);
     lq.Enqueue(22);
     lq.Enqueue(33);
     lq.Enqueue(44);
     lq.Dequeue();
 }
开发者ID:smihaylovit,项目名称:TelerikAkademy,代码行数:29,代码来源:Program.cs

示例7: Main

        /*
         * Implement the ADT queue as dynamic linked list. 
         * Use generics (LinkedQueue<T>) to allow storing different data types in the queue.
        */

        static void Main(string[] args)
        {
            ILinkedQueue<int> sample = new LinkedQueue<int>();

            sample.Enqueue(1);
            sample.Enqueue(2);
            sample.Enqueue(3);

            int[] sampleAsArray = sample.ToArray();

            Console.WriteLine("Queue as array:");
            for (int index = 0; index < sampleAsArray.Length; index++)
            {
                Console.WriteLine(sampleAsArray[index]);
            }

            Console.WriteLine("Dequeue + Peek");
            Console.WriteLine(sample.Dequeue() + " Dequeue");
            Console.WriteLine(sample.Dequeue() + " Dequeue");
            Console.WriteLine(sample.Peek() + " Peek");
            Console.WriteLine(sample.Dequeue() + " Dequeue");

            sample.Enqueue(4);
            Console.WriteLine("Does Contains 4? " + sample.Contains(4));

            sample.Enqueue(5);
            sample.Enqueue(6);

            sample.Clear();
            Console.WriteLine("Count after clear: " + sample.Count);
            // Console.WriteLine(sample.Dequeue()); // exception expected


        }
开发者ID:vaster,项目名称:Telerik.vasko,代码行数:39,代码来源:Program.cs

示例8: Main

        public static void Main()
        {
            var q = new LinkedQueue<int>();

            q.Enqueue(1);
            Console.WriteLine(q.Peek());
        }
开发者ID:mdamyanova,项目名称:Fundamental-Level,代码行数:7,代码来源:QueueMain.cs

示例9: EnqueueingElementShouldContainElement

        public void EnqueueingElementShouldContainElement()
        {
            var stack = new LinkedQueue<int>();

            stack.Enqueue(6);

            Assert.IsTrue(stack.Peek() == 6, "The stack must contain 6.");
            Assert.IsTrue(stack.Count == 1, "The stack count must be 1.");
        }
开发者ID:alex687,项目名称:SoftUni-Homeworks,代码行数:9,代码来源:LinkedQueueTests.cs

示例10: Main

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

        queue.Enqueue(1);
        queue.Enqueue(2);
        queue.Enqueue(3);
        queue.Enqueue(4);
        queue.Enqueue(5);

        Console.WriteLine("Queue count: " + queue.Count());
        Console.WriteLine("Top: " + queue.Peek());

        queue.Dequeue();
        Console.WriteLine("First deleted");
        Console.WriteLine("Queue count: " + queue.Count());
        Console.WriteLine("Top: " + queue.Peek());

        queue.Clear();
        Console.WriteLine("Queue cleared");
        Console.WriteLine("Queue count: " + queue.Count());
    }
开发者ID:sabrie,项目名称:TelerikAcademy,代码行数:22,代码来源:LinkedQueueDemo.cs

示例11: Main

        public static void Main(string[] args)
        {
            LinkedQueue<int> queue = new LinkedQueue<int>();
            Console.WriteLine("Queue count without elements: " + queue.Count);

            queue.Enqueue(1);
            queue.Enqueue(2);
            queue.Enqueue(3);

            Console.WriteLine("Queue count with 3 elements: " + queue.Count);
            Console.WriteLine("The front of the queue was: " + queue.Dequeue());
            Console.WriteLine("The front of the queue now is: " + queue.Peek());
        }
开发者ID:kalinnikol,项目名称:TelerikAcademy-1,代码行数:13,代码来源:LinkedQueueDemo.cs

示例12: Main

    static void Main()
    {
        LinkedQueue<string> names = new LinkedQueue<string>();

        names.Enqueue("Misho");
        names.Enqueue("Birata");

        Console.WriteLine(names.Dequeue());
        Console.WriteLine(names.Peek());
        Console.WriteLine(names.Count());
        Console.WriteLine(names.Contains("Misho"));
        Console.WriteLine(names.Contains("Birata"));
    }
开发者ID:VDGone,项目名称:TelerikAcademy-2,代码行数:13,代码来源:ADTQueueWithDynamicList.cs

示例13: Main

 static void Main(string[] args)
 {
     var queue = new LinkedQueue<int>();
     queue.Enqueue(1);
     Console.WriteLine(queue.Dequeue());
     Console.WriteLine(queue.Count);
     queue.Enqueue(2);
     queue.Enqueue(3);
     queue.Enqueue(4);
     queue.Enqueue(5);
     Console.WriteLine(queue.Peek());
     Console.WriteLine(queue.Count);
 }
开发者ID:Elinos,项目名称:TelerikAcademy,代码行数:13,代码来源:TaskThirteen.cs

示例14: Denqueue_PeekFirstOfFiveElements

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

            queue.Enqueue(10);
            queue.Enqueue(11);
            queue.Enqueue(12);
            queue.Enqueue(13);
            queue.Enqueue(14);

            int actual = queue.Peek();
            Assert.IsTrue(queue.Count == 5);
            Assert.IsTrue(actual == 10);
        }
开发者ID:BobbyBorisov,项目名称:TelerikAcademy,代码行数:14,代码来源:LinkedQueueTest.cs

示例15: Main

 public static void Main()
 {
     // Create LinkedQueue and test its methods
     QueueItem<string> element = new QueueItem<string>("a");
     LinkedQueue<string> queue = new LinkedQueue<string>(element);
     queue.Enqueue(new QueueItem<string>("b"));
     queue.Enqueue(new QueueItem<string>("c"));
     queue.Enqueue(new QueueItem<string>("d"));
     queue.Enqueue(new QueueItem<string>("e"));
     QueueItem<string> firstElement = queue.Dequeue();
     QueueItem<string> newFirstElement = queue.Peek();
     int count = queue.Count();
     bool hasElement = queue.Contains(new QueueItem<string>("z"));
 }
开发者ID:vasilkrvasilev,项目名称:DataStructuresAlgorithms,代码行数:14,代码来源:Example.cs


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