本文整理汇总了C#中System.Collections.Generic.PriorityQueue.First方法的典型用法代码示例。如果您正苦于以下问题:C# PriorityQueue.First方法的具体用法?C# PriorityQueue.First怎么用?C# PriorityQueue.First使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Generic.PriorityQueue
的用法示例。
在下文中一共展示了PriorityQueue.First方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PriorityQueue
public void PriorityQueue()
{
PriorityQueue<int> pq = new PriorityQueue<int>(LinqExt.TakeMore);
pq.Enqueue(1, 1);
pq.Enqueue(9, 9);
pq.Enqueue(2, 2);
pq.Enqueue(5, 5);
Assert.IsTrue(pq.First() == 9, "Wrong Priority");
Assert.IsTrue(pq.Dequeue() == 9, "Wrong Priority");
Assert.IsTrue(pq.Dequeue() == 5, "Wrong Priority");
pq.ChangePriority(1, 29);
Assert.IsTrue(pq.First() == 1, "Wrong Priority, 1 should be first priority now with priority 29");
pq.Enqueue(3, 2); //add item with same priority
pq.Enqueue(4, 2); //add item with same priority
Assert.IsTrue(pq.Last() == 4, "Wrong Priority, 4 should be last");
pq.Enqueue(30, 30); // mix case
Assert.IsTrue(pq.First() == 30, "Wrong Priority, 30 should be first priority");
pq.Enqueue(31, 30); // mix case
Assert.IsTrue(pq.First() == 30, "Wrong Priority, 30 should still be first priority");
pq.Enqueue(5, 2); //add item with same priority
pq.Enqueue(6, 2); //add item with same priority
Assert.IsTrue(pq.Last() == 6, "Wrong Priority, 6 should be last");
}
示例2: WorkPriorityQueue
public void WorkPriorityQueue()
{
var intPriorityQueue = new PriorityQueue<int>();
var stringPriorityQueue = new PriorityQueue<string>();
var userPriorityQueue = new PriorityQueue<User>();
try
{
intPriorityQueue.Enqueue(5, 1);
intPriorityQueue.Enqueue(40, 1);
Console.WriteLine("Number of elements of 1st order in queue = {0}", intPriorityQueue.GetCount(1));
Console.WriteLine("First element of 1st priority = {0}", intPriorityQueue.First());
Console.WriteLine("Last element of 1st priority = {0}", intPriorityQueue.Last());
intPriorityQueue.Dequeue();
intPriorityQueue.Enqueue(671, 2);
intPriorityQueue.Enqueue(30, 4);
intPriorityQueue.Enqueue(8932, 4);
Console.WriteLine("First element of 4th priority = {0}", intPriorityQueue.First(4));
Console.WriteLine("Last element of 4th priority = {0}", intPriorityQueue.Last(4));
Console.WriteLine("Queue length = {0}", intPriorityQueue.Count);
stringPriorityQueue.Enqueue("", 7);
stringPriorityQueue.Enqueue("40", 7);
//Console.WriteLine("Number of elements of 1st order in queue = {0}", stringPriorityQueue.GetCount(1));
Console.WriteLine("First element of 1st priority = {0}", stringPriorityQueue.First());
Console.WriteLine("Last element of 1st priority = {0}", stringPriorityQueue.Last());
stringPriorityQueue.Dequeue();
stringPriorityQueue.Enqueue("thirteen", 4);
stringPriorityQueue.Enqueue("god", 4);
Console.WriteLine("First element of 4th priority = {0}", stringPriorityQueue.First(4));
Console.WriteLine("Last element of 4th priority = {0}", stringPriorityQueue.Last(4));
Console.WriteLine("Queue length = {0}", stringPriorityQueue.Count);
userPriorityQueue.Enqueue(new User("Bardara", "Morgrad", new DateTime(1992, 12, 5)), 1);
userPriorityQueue.Enqueue(new User("Viki", "Crachkovic", new DateTime(1982, 2, 5)), 2);
Console.WriteLine("Number of elements of 1st order in queue = {0}", userPriorityQueue.GetCount(1));
Console.WriteLine("First element of 1st priority = {0}", userPriorityQueue.First().FullName);
Console.WriteLine("Last element of 1st priority = {0}", userPriorityQueue.Last().FullName);
userPriorityQueue.Dequeue();
userPriorityQueue.Enqueue(new User("Somalien", "Fred", new DateTime(1976, 12, 5)), 2);
//Console.WriteLine("First element of 4th priority = {0}", userPriorityQueue.First(4).FullName);
//Console.WriteLine("Last element of 4th priority = {0}", userPriorityQueue.Last(4).FullName);
Console.WriteLine("Queue length = {0}", userPriorityQueue.Count);
}
catch (Exception e)
{
Console.WriteLine("Exception occured - {0}", e.Message);
}
Console.ReadKey();
}
示例3: WorkPriorityQueue
public void WorkPriorityQueue()
{
Student firstStudent = new Student("Alina", "Kylish", 123456789, new DateTime(1988, 4, 3));
Student secondStudent = new Student("Elena", "Kylish", 987654321, new DateTime(1987, 8, 15));
Student thirdStudent = new Student("Oleg", "Ivanov", 975312468, new DateTime(1992, 11, 20));
Student fourthStudent = new Student("Andrey", "Pavlov", 1243576890, new DateTime(1977, 8, 10));
PriorityQueue<Student> students = new PriorityQueue<Student>();
students.Enqueue(firstStudent, 0);
students.Enqueue(secondStudent, 1);
students.Enqueue(thirdStudent, 2);
students.Enqueue(fourthStudent, 0);
Console.WriteLine(students.Count());
Console.WriteLine(students.First());
Console.WriteLine(students.Last());
students.Dequeue();
Console.WriteLine(students.Count());
Console.ReadKey();
students.Clear();
students.Dequeue(); // throw exeption with message "Queue is empty. There is no value in queue"
}
示例4: WorkWithPriorityQueue
static void WorkWithPriorityQueue()
{
PriorityQueue<int> numbers = new PriorityQueue<int>();
try
{
Console.WriteLine("Count = {0}", numbers.Count());
//Console.WriteLine(numbers.First());
//Console.WriteLine(numbers.Last());
//numbers.Add(10);
// Print(numbers);
numbers.Enqueue(1, 5);
numbers.Enqueue(2, 11);
numbers.Enqueue(1, 1);
// Print(numbers);
numbers.Enqueue(2, 1);
numbers.Enqueue(3, 1);
numbers.Enqueue(15, 2);
numbers.Enqueue(25, 2);
numbers.Enqueue(21, 2);
// Print(numbers);
numbers.Enqueue(1021, 3);
numbers.Enqueue(375, 5);
numbers.Enqueue(124243323, 8);
// Print(numbers);
Console.WriteLine("Count = {0}", numbers.Count());
Console.WriteLine("Count with priority 1= {0}", numbers.GetCount(1));
Console.WriteLine("Count with priority 2= {0}", numbers.GetCount(2));
Console.WriteLine("Count with priority 3= {0}", numbers.GetCount(3));
Console.WriteLine("Count with priority 4= {0}", numbers.GetCount(4));
Console.WriteLine("Count with priority 5= {0}", numbers.GetCount(5));
Console.WriteLine("Count with priority 8= {0}", numbers.GetCount(8));
Console.WriteLine("Count with priority 11= {0}", numbers.GetCount(11));
Console.WriteLine(numbers.First());
Console.WriteLine(numbers.Last());
Console.WriteLine(numbers.Dequeue());
// Print(numbers);
Console.WriteLine(numbers.Dequeue());
Console.WriteLine(numbers.Dequeue());
Console.WriteLine(numbers.Dequeue());
// Print(numbers);
Console.WriteLine(numbers.Dequeue());
Console.WriteLine(numbers.Dequeue());
Console.WriteLine(numbers.Dequeue());
// Print(numbers);
Console.WriteLine("Count = {0}", numbers.Count());
Console.WriteLine("Count with priority 1= {0}", numbers.GetCount(1));
Console.WriteLine("Count with priority 2= {0}", numbers.GetCount(2));
Console.WriteLine("Count with priority 3= {0}", numbers.GetCount(3));
Console.WriteLine("Count with priority 4= {0}", numbers.GetCount(4));
Console.WriteLine("Count with priority 5= {0}", numbers.GetCount(5));
Console.WriteLine("Count with priority 8= {0}", numbers.GetCount(8));
Console.WriteLine("Count with priority 11= {0}", numbers.GetCount(11));
numbers.Clear();
Console.WriteLine("Count = {0}", numbers.Count<int>());
// Print(numbers);
numbers.Add(10);
numbers.Add(11);
Console.WriteLine(numbers.First());
Console.WriteLine(numbers.Last());
Console.WriteLine();
numbers.Enqueue(1, 5);
numbers.Add(5);
Print(numbers);
Console.WriteLine();
}
catch
{
Console.WriteLine("Is Exeption");
}
Console.ReadKey();
}
示例5: 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();
}