本文整理汇总了C#中PriorityQueue.Peek方法的典型用法代码示例。如果您正苦于以下问题:C# PriorityQueue.Peek方法的具体用法?C# PriorityQueue.Peek怎么用?C# PriorityQueue.Peek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PriorityQueue
的用法示例。
在下文中一共展示了PriorityQueue.Peek方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RandomTest
public void RandomTest()
{
PriorityQueue<int> TestObject = new PriorityQueue<int>();
Utilities.Random.Random Rand = new Utilities.Random.Random();
int Value=0;
for (int x = 0; x < 10; ++x)
{
Value=Rand.Next();
TestObject.Add(x, Value);
Assert.Equal(Value, TestObject.Peek());
}
int HighestValue = TestObject.Peek();
for (int x = 9; x >= 0; --x)
{
Value = Rand.Next();
TestObject.Add(x, Value);
Assert.Equal(HighestValue, TestObject.Peek());
}
int Count=0;
foreach(int Priority in TestObject.Keys)
{
foreach(int Item in TestObject[Priority])
{
++Count;
}
}
Assert.Equal(20, Count);
}
示例2: SimpleWithPriority
public void SimpleWithPriority()
{
var priorityQueue = new PriorityQueue<string, int>(PriorityQueueType.Minimum);
int priority;
priorityQueue.Enqueue("g", 6);
var item = priorityQueue.Peek(out priority);
Assert.AreEqual(item, "g");
Assert.AreEqual(priority, 6);
Assert.AreEqual(priorityQueue.Count, 1);
priorityQueue.Enqueue("h", 5);
item = priorityQueue.Peek(out priority);
Assert.AreEqual(item, "h");
Assert.AreEqual(priority, 5);
Assert.AreEqual(priorityQueue.Count, 2);
priorityQueue.Enqueue("i", 7);
item = priorityQueue.Peek(out priority);
Assert.AreEqual(item, "h");
Assert.AreEqual(priority, 5);
Assert.AreEqual(priorityQueue.Count, 3);
}
示例3: PriorityQueueGeneralTest
public void PriorityQueueGeneralTest()
{
var queue = new PriorityQueue<int>();
Assert.IsTrue(queue.Empty, "New queue should start out empty.");
Assert.Throws<InvalidOperationException>(() => queue.Peek(), "Peeking at an empty queue should throw.");
Assert.Throws<InvalidOperationException>(() => queue.Pop(), "Popping an empty queue should throw.");
foreach (var value in new[] { 4, 3, 5, 1, 2 })
{
queue.Add(value);
Assert.IsFalse(queue.Empty, "Queue should not be empty - items have been added.");
}
foreach (var value in new[] { 1, 2, 3, 4, 5 })
{
Assert.AreEqual(value, queue.Peek(), "Peek returned the wrong item - should be in order.");
Assert.IsFalse(queue.Empty, "Queue should not be empty yet.");
Assert.AreEqual(value, queue.Pop(), "Pop returned the wrong item - should be in order.");
}
Assert.IsTrue(queue.Empty, "Queue should now be empty.");
Assert.Throws<InvalidOperationException>(() => queue.Peek(), "Peeking at an empty queue should throw.");
Assert.Throws<InvalidOperationException>(() => queue.Pop(), "Popping an empty queue should throw.");
}
示例4: Simple
public void Simple()
{
var priorityQueue = new PriorityQueue<string, int>(PriorityQueueType.Minimum);
priorityQueue.Enqueue("g", 6);
Assert.AreEqual(priorityQueue.Peek(), "g");
priorityQueue.Enqueue("h", 5);
Assert.AreEqual(priorityQueue.Peek(), "h");
priorityQueue.Enqueue("i", 7);
Assert.AreEqual(priorityQueue.Peek(), "h");
}
示例5: Main
public static void Main()
{
PriorityQueue<int> pq = new PriorityQueue<int>();
pq.Enque(2);
pq.Enque(3);
pq.Enque(4);
pq.Enque(1);
Console.WriteLine(pq.Peek());
Console.WriteLine(pq.Deque());
Console.WriteLine(pq.Peek());
Console.WriteLine(pq.Count);
}
示例6: AssertDequeues
public void AssertDequeues(PriorityQueue<int> queue, params int[] values)
{
for (int i = 0; i < values.Length; i++)
{
Assert.AreEqual(values.Length - i, queue.Count);
Assert.AreEqual(values[i], queue.Peek());
Assert.AreEqual(values[i], queue.Peek());
Assert.AreEqual(values[i], queue.Dequeue());
Assert.AreEqual(values.Length - i - 1, queue.Count);
AssertQueueProperty(queue);
}
}
示例7: Main
private static void Main()
{
var items = new[] { 2, 6, 3, 2, 1, 7, 4, 9, 5, 1, 8 };
Console.WriteLine("Items: [{0}]", string.Join(", ", items));
// Priority queue of integers, where a lower number means higher priority
var queue = new PriorityQueue<int>();
// Add each item to the priority queue and
// check if the item with the highest priority is at the top of the queue
var minItem = int.MaxValue;
foreach (var item in items)
{
queue.Enqueue(item);
minItem = Math.Min(item, minItem);
Debug.Assert(queue.Peek() == minItem);
}
// Now check if after each dequeue, the items come out ranked by priority
var sorted = new List<int>();
while (queue.Count > 0)
{
sorted.Add(queue.Dequeue());
}
// Items should be sorted in ascending order
Console.WriteLine("Queue items: [{0}]", string.Join(", ", sorted));
}
示例8: PriorityQueuePeekTest
public void PriorityQueuePeekTest()
{
PriorityQueue<int> queue = new PriorityQueue<int> ();
queue.Enqueue (5, 3);
queue.Enqueue (6, 2);
Assert.AreEqual (6, queue.Peek ());
}
示例9: Main
public static void Main()
{
var queue = new PriorityQueue<int>();
queue.Enqueue(6);
queue.Enqueue(5);
queue.Enqueue(3);
Console.WriteLine(queue.Peek());
queue.Enqueue(1);
queue.Enqueue(8);
queue.Enqueue(7);
queue.Enqueue(2);
queue.Enqueue(4);
Console.WriteLine(queue.Peek());
while (queue.Size > 0)
{
Console.WriteLine(queue.Dequeue());
}
}
示例10: PeekFirstAndOnlyElementTest
public void PeekFirstAndOnlyElementTest()
{
PriorityQueue<string> queue = new PriorityQueue<string>();
queue.Enqueue("Pesho");
string peeked = queue.Peek();
Assert.AreEqual(1, queue.Count);
Assert.AreEqual("Pesho", peeked);
}
示例11: Main
static void Main()
{
PriorityQueue<int, int> priorityQueue = new PriorityQueue<int, int>();
priorityQueue.Enqueue(1, 10);
priorityQueue.Enqueue(5, 12);
priorityQueue.Enqueue(2, 13);
priorityQueue.Enqueue(4, 14);
priorityQueue.Enqueue(3, 15);
Console.WriteLine("Peek at biggest element: {0} ", priorityQueue.Peek());
priorityQueue.Dequeue();
Console.WriteLine("Peek after dequeue: {0}", priorityQueue.Peek());
priorityQueue.Enqueue(5, 15);
priorityQueue.Enqueue(2, 20);
Console.WriteLine("Biggest element after enqueue: {0} ", priorityQueue.Peek());
}
示例12: Main
static void Main()
{
PriorityQueue<int> siabongasPriorityQueue = new PriorityQueue<int>();
siabongasPriorityQueue.Enqueue(10);
siabongasPriorityQueue.Enqueue(12);
siabongasPriorityQueue.Enqueue(15);
siabongasPriorityQueue.Enqueue(14);
siabongasPriorityQueue.Enqueue(13);
Console.WriteLine("Peek is: {0} ", siabongasPriorityQueue.Peek());
siabongasPriorityQueue.Dequeue();
Console.WriteLine("Peek after dequeue is: {0}", siabongasPriorityQueue.Peek());
siabongasPriorityQueue.Enqueue(15);
siabongasPriorityQueue.Enqueue(20);
siabongasPriorityQueue.Enqueue(12);
siabongasPriorityQueue.Enqueue(11);
Console.WriteLine("Peak after few more enqueues is: {0} ", siabongasPriorityQueue.Peek());
}
开发者ID:stoyanovalexander,项目名称:TheRepositoryOfAlexanderStoyanov,代码行数:20,代码来源:ImplementPriorityQueue.cs
示例13: Main
public static void Main(string[] args)
{
var priorityQueue = new PriorityQueue<int>();
priorityQueue.Enqueue(3, 3);
priorityQueue.Enqueue(3, 3);
priorityQueue.Enqueue(4, 4);
priorityQueue.Dequeue();
priorityQueue.Dequeue();
Console.WriteLine(priorityQueue.Peek());
}
示例14: Test_Enqueue
public void Test_Enqueue()
{
var pq = new PriorityQueue<int>();
var minItem = int.MaxValue;
foreach (var item in items)
{
pq.Enqueue(item);
minItem = Math.Min(item, minItem);
Assert.AreEqual(pq.Peek(), minItem);
}
}
示例15: TestInsertionDescending
public void TestInsertionDescending()
{
var priorityQueue = new PriorityQueue<int>();
for (int i = 0; i < 1000; ++i)
{
priorityQueue.Enqueue(999 - i);
}
Assert.That(priorityQueue.Count, Is.EqualTo(1000));
Assert.That(priorityQueue.Peek(), Is.EqualTo(0));
CheckPriorityQueue(priorityQueue);
}