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


C# PriorityQueue.CopyTo方法代码示例

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


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

示例1: WorkPriorityQueue

        public void WorkPriorityQueue()
        {
            PriorityQueue<string> q1 = new PriorityQueue<string>();
            PriorityQueue<int> q2 = new PriorityQueue<int>();
            PriorityQueue<Group> q3 = new PriorityQueue<Group>();

            q1.Enqueue(new List<string> { "A", "B", "C" }, 5);
            q1.Enqueue(new List<string> { "F", "G", "H" }, 1);
            q1.Enqueue(new List<string> { "X", "V", "B" }, 0);
            q1.Enqueue(new List<string> { "Q", "W", "E" }, 1);
            q1.Enqueue("Z", 1);

            q2.Enqueue(new List<int> { 4, 5, 6 }, 5);
            q2.Enqueue(new List<int> { 1, 2, 3 }, 1);
            q2.Enqueue(new List<int> { 7, 8, 9 }, 0);
            q2.Enqueue(new List<int> { 0, 3, 5 }, 1);
            q2.Enqueue(9, 2);

            q3.Enqueue(new Group("CS1", 7), 1);
            q3.Enqueue(new Group("CS2", 14), 3);
            q3.Enqueue(new Group("CS3", 24), 5);
            q3.Enqueue(new Group("CS4", 31), 1);

            Console.WriteLine("Dequeue in Q1: " + q1.Dequeue());
            Console.WriteLine("First in Q1: " + q1.First());
            Console.WriteLine("First with priority = 1 in Q1: " + q1.First(1));
            Console.WriteLine("Last in Q1: " + q1.Last());
            Console.WriteLine("Last with priority = 1 in Q1: " + q1.Last(1));
            Console.WriteLine("Count in Q1: " + q1.Count);
            Console.WriteLine("Count with priority = 1 in Q1: " + q1.GetCount(1));

            Console.WriteLine("__________________________________________________");

            Console.WriteLine("Dequeue in Q2: " + q2.Dequeue());
            Console.WriteLine("First in Q2: " + q2.First());
            Console.WriteLine("First with priority = 1 in Q2: " + q2.First(1));
            Console.WriteLine("Last in Q2: " + q2.Last());
            Console.WriteLine("Last with priority = 1 in Q2: " + q2.Last(1));
            Console.WriteLine("Count in Q2: " + q2.Count);
            Console.WriteLine("Count with priority = 1 in Q2: " + q2.GetCount(1));

            Console.WriteLine("__________________________________________________");

            Console.WriteLine("Dequeue in Q3: " + q3.Dequeue().Title);
            Console.WriteLine("First in Q3: " + q3.First().Title);
            Console.WriteLine("First with priority = 1 in Q3: " + q3.First(1).Title);
            Console.WriteLine("Last in Q3: " + q3.Last().Title);
            Console.WriteLine("Last with priority = 1 in Q3: " + q3.Last(1).Title);
            Console.WriteLine("Count in Q3: " + q3.Count);
            Console.WriteLine("Count with priority = 1 in Q3: " + q3.GetCount(1));

            Console.WriteLine("__________________________________________________");
            bool q = q1.Contains(new Tuple<string, int>("7", 1));
            Console.WriteLine("Contains('7', 1) in Q1: " + q);
            q = q1.Contains(new Tuple<string, int>("Z", 1));
            Console.WriteLine("Contains('Z', 1) in Q1: " + q);

            q2.Clear();
            Console.WriteLine("Clear in Q2: " + q2.Count);

            Tuple<string, int>[] array = new Tuple<string, int>[15];

            q1.CopyTo(array, 0);

            for (int i = 0; i < array.Length; i++)
            {
                Console.WriteLine("Array[{0}] = ( {1}  {2})", i, array[i].Item2, array[i].Item1);
            }

            Console.ReadLine();
        }
开发者ID:SalamanderSunburn,项目名称:tasks_cs1,代码行数:71,代码来源:CollectionsExercises.cs

示例2: ExceptionNullArray

 public void ExceptionNullArray()
 {
     var priorityQueue = new PriorityQueue<string, int>(PriorityQueueType.Minimum);
     priorityQueue.CopyTo(null, 0);
 }
开发者ID:GTuritto,项目名称:ngenerics,代码行数:5,代码来源:CopyTo.cs

示例3: TestCopyTo

        public void TestCopyTo()
        {
            var queue = new PriorityQueue<string> { "string", "anotherString" };
            var array = new string[3];

            queue.CopyTo(array, 1);

            Assert.IsNull(array[0]);
            Assert.AreEqual("anotherString", array[1]);
            Assert.AreEqual("string", array[2]);
        }
开发者ID:pkubryk,项目名称:SummerBatch,代码行数:11,代码来源:PriorityQueueTest.cs


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