mirror of
https://github.com/krahets/hello-algo.git
synced 2024-12-24 04:26:30 +08:00
fix(csharp): priority queue comparer initialization (#1542)
This commit is contained in:
parent
68a61f23d5
commit
b3b10f2300
2 changed files with 4 additions and 4 deletions
|
@ -24,8 +24,8 @@ public class heap {
|
|||
/* 初始化堆 */
|
||||
// 初始化小顶堆
|
||||
PriorityQueue<int, int> minHeap = new();
|
||||
// 初始化大顶堆(使用 lambda 表达式修改 Comparator 即可)
|
||||
PriorityQueue<int, int> maxHeap = new(Comparer<int>.Create((x, y) => y - x));
|
||||
// 初始化大顶堆(使用 lambda 表达式修改 Comparer 即可)
|
||||
PriorityQueue<int, int> maxHeap = new(Comparer<int>.Create((x, y) => y.CompareTo(x)));
|
||||
Console.WriteLine("以下测试样例为大顶堆");
|
||||
|
||||
/* 元素入堆 */
|
||||
|
|
|
@ -157,8 +157,8 @@
|
|||
/* 初始化堆 */
|
||||
// 初始化小顶堆
|
||||
PriorityQueue<int, int> minHeap = new();
|
||||
// 初始化大顶堆(使用 lambda 表达式修改 Comparator 即可)
|
||||
PriorityQueue<int, int> maxHeap = new(Comparer<int>.Create((x, y) => y - x));
|
||||
// 初始化大顶堆(使用 lambda 表达式修改 Comparer 即可)
|
||||
PriorityQueue<int, int> maxHeap = new(Comparer<int>.Create((x, y) => y.CompareTo(x)));
|
||||
|
||||
/* 元素入堆 */
|
||||
maxHeap.Enqueue(1, 1);
|
||||
|
|
Loading…
Reference in a new issue