本文整理汇总了C#中System.Collections.Generic.PriorityQueue.Peek方法的典型用法代码示例。如果您正苦于以下问题:C# PriorityQueue.Peek方法的具体用法?C# PriorityQueue.Peek怎么用?C# PriorityQueue.Peek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Generic.PriorityQueue
的用法示例。
在下文中一共展示了PriorityQueue.Peek方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestBasicFunctionality
public void TestBasicFunctionality()
{
var q = new PriorityQueue<int>();
Assert.AreEqual(0, q.Count);
Assert.AreEqual(0, q.Capacity);
Assert.Throws<InvalidOperationException>(() => q.Peek());
Assert.Throws<InvalidOperationException>(() => q.Dequeue());
q.Enqueue(5);
q.Enqueue(2);
q.Enqueue(4);
Assert.AreEqual(3, q.Count);
Assert.IsTrue(q.Capacity >= 3);
Assert.IsTrue(q.Contains(2));
Assert.IsFalse(q.Contains(3));
Assert.AreEqual(3, q.ToArray().Length);
CollectionAssert.AreEqual(q.ToArray(), q);
Assert.AreEqual(2, q.Peek());
Assert.AreEqual(2, q.Dequeue());
Assert.AreEqual(4, q.Dequeue());
Assert.AreEqual(5, q.Dequeue());
}
示例2: Clear
public void Clear()
{
var pq = new PriorityQueue<int>(new int[] { 1, 2, 3 });
int temp;
Assert.AreEqual(3, pq.Count);
Assert.IsTrue(pq.Peek(out temp));
pq.Clear();
Assert.AreEqual(0, pq.Count);
Assert.IsFalse(pq.Peek(out temp));
}
示例3: PriorityQueuePeekQueueNoChangeInCount
public void PriorityQueuePeekQueueNoChangeInCount()
{
var q = new PriorityQueue<int>();
q.Enqueue(AnyInt);
var count = q.Count;
q.Peek();
Assert.Equal(count, q.Count);
}
示例4: Peek
public void Peek()
{
var pq = new PriorityQueue<int>(new int[] {1, 2, 3});
int temp;
Assert.IsTrue(pq.Peek(out temp));
Assert.AreEqual(1, temp);
Assert.AreEqual(1, pq.Dequeue());
Assert.IsTrue(pq.Peek(out temp));
Assert.AreEqual(2, temp);
}
示例5: PriorityQueueClearEmptiesTheQueue
public void PriorityQueueClearEmptiesTheQueue()
{
var q = new PriorityQueue<int>();
q.Enqueue(AnyInt);
q.Enqueue(AnyInt);
q.Clear();
Assert.Equal(0, q.Count);
Assert.Throws<InvalidOperationException>(() => q.Peek());
}
示例6: DijkstraAlgorithm
static void DijkstraAlgorithm(Dictionary<Node, List<Connection>> graph, Node source)
{
PriorityQueue<Node> queue = new PriorityQueue<Node>();
foreach (var node in graph)
{
if (source.ID != node.Key.ID)
{
node.Key.DijkstraDistance = double.PositiveInfinity;
queue.Enqueue(node.Key);
}
}
source.DijkstraDistance = 0.0d;
queue.Enqueue(source);
while (queue.Count != 0)
{
Node currentNode = queue.Peek();
if (currentNode.DijkstraDistance == double.PositiveInfinity)
{
break;
}
foreach (var neighbour in graph[currentNode])
{
double potDistance = currentNode.DijkstraDistance + neighbour.Distance;
if (potDistance < neighbour.Node.DijkstraDistance)
{
neighbour.Node.DijkstraDistance = potDistance;
}
}
queue.Dequeue();
}
}
示例7: TestPeek1
public void TestPeek1()
{
var queue = new PriorityQueue<string> { "string", "anotherString" };
var poll = queue.Peek();
Assert.AreEqual(2, queue.Count);
Assert.AreEqual("anotherString", poll);
Assert.IsTrue(queue.Contains("anotherString"));
}
示例8: DequeueTestString
public void DequeueTestString([PexAssumeUnderTest]List<string> elementList)
{
PriorityQueue<string> actual = new PriorityQueue<string>(elementList);
string dequeuedElem = actual.Dequeue();
elementList.Sort();
PexAssert.AreEqual(elementList[0], dequeuedElem);
if (elementList.Count > 1)
PexAssert.AreEqual(elementList[1], actual.Peek());
PexAssert.AreEqual(elementList.Count - 1, actual.Count);
}
示例9: PriorityQueuePeekEmptyQueueThrowsException
public void PriorityQueuePeekEmptyQueueThrowsException()
{
var q = new PriorityQueue<int>();
Assert.Equal(0, q.Count);
Assert.Throws<InvalidOperationException>(() => q.Peek());
}
示例10: TestPeek2
public void TestPeek2()
{
var queue = new PriorityQueue<string>();
var poll = queue.Peek();
Assert.IsNull(poll);
}
示例11: SimpleTest
public void SimpleTest()
{
var queue = new PriorityQueue<int, int>();
Assert.IsFalse(queue.HasItems);
queue.Enqueue(1, 10);
queue.Enqueue(3, 30);
queue.Enqueue(5, 50);
queue.Enqueue(4, 40);
queue.Enqueue(2, 20);
Assert.IsTrue(queue.HasItems);
Assert.AreEqual(50, queue.Peek());
Assert.AreEqual(50, queue.Peek());
Assert.AreEqual(50, queue.Dequeue());
Assert.AreEqual(40, queue.Peek());
Assert.AreEqual(40, queue.Dequeue());
Assert.IsTrue(queue.HasItems);
Assert.AreEqual(30, queue.Peek());
Assert.AreEqual(30, queue.Peek());
Assert.AreEqual(30, queue.Peek());
Assert.AreEqual(30, queue.Dequeue());
Assert.IsTrue(queue.HasItems);
Assert.AreEqual(20, queue.Peek());
Assert.AreEqual(20, queue.Dequeue());
Assert.AreEqual(10, queue.Peek());
Assert.AreEqual(10, queue.Peek());
Assert.AreEqual(10, queue.Peek());
Assert.AreEqual(10, queue.Peek());
Assert.AreEqual(10, queue.Peek());
Assert.IsTrue(queue.HasItems);
Assert.AreEqual(10, queue.Peek());
Assert.AreEqual(10, queue.Dequeue());
Assert.IsFalse(queue.HasItems);
}
示例12: TestPeek
public void TestPeek()
{
PriorityQueue<int, int> q = new PriorityQueue<int, int>();
q.Enqueue(2, 2);
q.Enqueue(1, 1);
Assert.AreEqual(1, q.Peek());
Assert.AreEqual(2, q.Count);
}
示例13: PeekTest
public void PeekTest()
{
PriorityQueue<int> actual = new PriorityQueue<int> { 12, 6, 3, 1, 0, 8 };
Assert.AreEqual(0, actual.Peek());
}
示例14: ReInsert
protected virtual void ReInsert(Node node, Int32 level)
{
MinimumBoundingBox nodeBox = node.CalculateMinimumBoundingBox();
PriorityQueue<NodeEntry, Single> distances = new PriorityQueue<NodeEntry, Single>(),
reInsertions = new PriorityQueue<NodeEntry, Single>();
foreach (NodeEntry entry in node.NodeEntries)
distances.Enqueue(entry, GetCenterDistance(nodeBox, entry.MinimumBoundingBox) * -1);
for (int i = 0; i < Constants.NODES_FOR_REINSERT; i++)
reInsertions.Enqueue(distances.Peek().Value, distances.Dequeue().Priority * -1);
foreach (PriorityQueueItem<NodeEntry, Single> entry in reInsertions)
node.RemoveNodeEntry(entry.Value);
AdjustTree(node, level);
while(reInsertions.Count > 0)
Insert(reInsertions.Dequeue().Value, level);
}
示例15: MaxValuesHavePriorityTest
public void MaxValuesHavePriorityTest()
{
PriorityQueue<int> actual = new PriorityQueue<int>(Strategy.Max) { 6, 1, 8, 9, 2, 3, 7 };
Assert.AreEqual(9, actual.Peek());
}