本文整理汇总了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();
}
示例2: ExceptionNullArray
public void ExceptionNullArray()
{
var priorityQueue = new PriorityQueue<string, int>(PriorityQueueType.Minimum);
priorityQueue.CopyTo(null, 0);
}
示例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]);
}