本文整理汇总了C#中PriorityQueue.Top方法的典型用法代码示例。如果您正苦于以下问题:C# PriorityQueue.Top方法的具体用法?C# PriorityQueue.Top怎么用?C# PriorityQueue.Top使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PriorityQueue
的用法示例。
在下文中一共展示了PriorityQueue.Top方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestMethodPushAndTop
public void TestMethodPushAndTop()
{
PriorityQueue<double> testQueue = new PriorityQueue<double>();
testQueue.Push(1, 2);
testQueue.Push(2, 2);
testQueue.Push(1, 3);
Assert.IsTrue(testQueue.Top() == 2);
}
示例2: Dijkstra
static double Dijkstra(List<List<double>> t, List<List<int>> c, int x, int y, double speed)
{
int[] dx = new int[] {0, 1, 0, -1};
int[] dy = new int[] {1, 0, -1, 0};
int h = t.Count, w = t[0].Count;
bool[,,] seen = new bool[h, w, 2];
double[,,] dist = new double[h, w, 2];
foreach (int i in Enumerable.Range(0, h))
foreach (int j in Enumerable.Range(0, w))
foreach (int k in Enumerable.Range(0, 2))
dist[i, j, k] = 13;
foreach (int k in Enumerable.Range(0, 2))
{
dist[x, y, k] = 0;
PriorityQueue q = new PriorityQueue();
q.Enqueue(Tuple.Create(0.0, x, y));
while (!q.Empty())
{
var best = q.Top();
q.Dequeue();
if (seen[best.Item2, best.Item3, k]) continue;
seen[best.Item2, best.Item3, k] = true;
foreach (var z in Enumerable.Range(0, 4)
.Select(l => new {X = best.Item2 + dx[l], Y = best.Item3 + dy[l]})
.Where(z => z.X >= 0 && z.X < h && z.Y >= 0 && z.Y < w &&
Math.Abs(c[best.Item2][best.Item3] - c[z.X][z.Y]) <= 1000))
{
double ndist = speed +
Math.Max(t[z.X][z.Y] + Convert.ToInt32(k == 0), best.Item1);
if (ndist < dist[z.X, z.Y, k])
{
dist[z.X, z.Y, k] = ndist;
q.Enqueue(Tuple.Create(dist[z.X, z.Y, k], z.X, z.Y));
}
}
}
}
return (
from i in Enumerable.Range(0, h)
from j in Enumerable.Range(0, w)
where dist[i, j, 0] <= 12 - dist[i, j, 1]
select Math.Sqrt((i - x) * (i - x) + (j - y) * (j - y))
).Max();
}
示例3: TestMethodTopOnException
public void TestMethodTopOnException()
{
PriorityQueue<double> testQueue = new PriorityQueue<double>();
testQueue.Top();
}