本文整理汇总了C#中PriorityQueue.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# PriorityQueue.ToString方法的具体用法?C# PriorityQueue.ToString怎么用?C# PriorityQueue.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PriorityQueue
的用法示例。
在下文中一共展示了PriorityQueue.ToString方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
/// <summary>
/// Based on the article "Priority Queues with C#" by James McCaffrey:
/// http://visualstudiomagazine.com/articles/2012/11/01/priority-queues-with-c.aspx
/// </summary>
private static void Main()
{
Console.WriteLine("\nBegin Priority Queue demo");
Console.WriteLine("\nCreating priority queue of Employee items\n");
PriorityQueue<Employee> queue = new PriorityQueue<Employee>();
Employee e1 = new Employee("Aiden", 1.0);
Employee e2 = new Employee("Baker", 2.0);
Employee e3 = new Employee("Chung", 3.0);
Employee e4 = new Employee("Dunne", 4.0);
Employee e5 = new Employee("Eason", 5.0);
Employee e6 = new Employee("Flynn", 6.0);
Console.WriteLine("Adding " + e5.ToString() + " to priority queue");
queue.Enqueue(e5);
Console.WriteLine("Adding " + e3.ToString() + " to priority queue");
queue.Enqueue(e3);
Console.WriteLine("Adding " + e6.ToString() + " to priority queue");
queue.Enqueue(e6);
Console.WriteLine("Adding " + e4.ToString() + " to priority queue");
queue.Enqueue(e4);
Console.WriteLine("Adding " + e1.ToString() + " to priority queue");
queue.Enqueue(e1);
Console.WriteLine("Adding " + e2.ToString() + " to priority queue");
queue.Enqueue(e2);
Console.WriteLine("\nPriory queue is: ");
Console.WriteLine(queue.ToString());
Console.WriteLine("\n");
Console.WriteLine("Removing an employee from priority queue");
Employee e = queue.Dequeue();
Console.WriteLine("Removed employee is " + e.ToString());
Console.WriteLine("\nPriory queue is now: ");
Console.WriteLine(queue.ToString());
Console.WriteLine("\n");
Console.WriteLine("Removing a second employee from queue");
e = queue.Dequeue();
Console.WriteLine("\nPriory queue is now: ");
Console.WriteLine(queue.ToString());
Console.WriteLine("\n");
}
示例2: TestEnqueueEmptyQueue
public void TestEnqueueEmptyQueue()
{
PriorityQueue<Char> queue = new PriorityQueue<Char>();
queue.Enqueue ('a', 1);
String output = queue.ToString();
Assert.IsTrue ("[ 1. a ]".Equals(output));
}
示例3: TestFirstTakePrecedence1
public void TestFirstTakePrecedence1()
{
PriorityQueue<Char> queue = new PriorityQueue<Char>();
queue.Enqueue ('b', 1);
queue.Enqueue ('a', 0);
String output = queue.ToString();
Assert.IsTrue ("[ 0. a, 1. b ]".Equals(output));
}
示例4: TestFirstTakePrecedence2
public void TestFirstTakePrecedence2()
{
PriorityQueue<Char> queue = new PriorityQueue<Char>();
queue.Enqueue ('d', 3);
queue.Enqueue ('b', 2);
queue.Enqueue ('c', 2);
queue.Enqueue ('a', 1);
String output = queue.ToString();
Assert.IsTrue ("[ 1. a, 2. b, 2. c, 3. d ]".Equals(output));
}
示例5: TestDequeueNotEmptyQueue
public void TestDequeueNotEmptyQueue()
{
PriorityQueue<Char> queue = new PriorityQueue<Char>();
queue.Enqueue ('a', 1);
queue.Enqueue ('b', 1);
queue.Enqueue ('c', 1);
queue.Enqueue ('d', 1);
Char firstElement = queue.Dequeue();
String output = queue.ToString();
Assert.IsTrue ('a' == firstElement);
Assert.IsTrue ("[ 1. b, 1. c, 1. d ]".Equals(output));
}
示例6: Main
static void Main(string[] args)
{
PriorityQueue<int> heap = new PriorityQueue<int>(2);
heap.Enqueue(1);
heap.Enqueue(21);
heap.Enqueue(3);
heap.Enqueue(6);
Console.WriteLine(heap.Dequeue());
heap.Enqueue(31);
heap.Enqueue(5);
Console.WriteLine("ToString elements");
Console.WriteLine(heap.ToString());
Console.WriteLine("Dequeue elements");
while (heap.Count > 0)
{
Console.Write("{0}, ", heap.Dequeue());
}
}
示例7: PrintQueue
private static void PrintQueue(PriorityQueue<int> priorityQueue)
{
Console.WriteLine(priorityQueue.ToString());
}
示例8: PriorityQueue_ToString_EmptyCollection_Success
public void PriorityQueue_ToString_EmptyCollection_Success()
{
// Arrange
var priorityQueue = new PriorityQueue<int>();
var expected = "";
// Act
var result = priorityQueue.ToString();
// Assert
Assert.AreEqual(result, expected);
}
示例9: PriorityQueue_Enqueue_RepeatedValues_Success
public void PriorityQueue_Enqueue_RepeatedValues_Success()
{
// Arrange
var priorityQueue = new PriorityQueue<int>();
var values = new int[] { 10, 5, 6, 1, 2, 3, 6, 4, 5, 8 };
var expected = "1,2,3,4,5,6,6,10,5,8";
// Act
foreach (var value in values)
{
priorityQueue.Enqueue(value);
}
var result = priorityQueue.ToString();
// Assert
Assert.AreEqual(result, expected);
}
示例10: TestLessPriority
public void TestLessPriority()
{
PriorityQueue<Char> queue = new PriorityQueue<Char>();
queue.Enqueue ('a', 1);
queue.Enqueue ('b', 1);
queue.Enqueue ('c', 1);
queue.Enqueue ('d', 1);
String output = queue.ToString();
Assert.IsTrue ("[ 1. a, 1. b, 1. c, 1. d ]".Equals(output));
}
示例11: TestToString
public void TestToString()
{
PriorityQueue<Char> queue = new PriorityQueue<Char>();
queue.Enqueue ('a', 1);
queue.Enqueue ('c', 1);
queue.Enqueue ('c', 1);
queue.Enqueue ('d', 1);
String output = queue.ToString();
System.Console.WriteLine(output);
Assert.IsTrue ("[ 1. a, 1. c, 1. c, 1. d ]".Equals(output));
}