Skip to content

Commit

Permalink
fix(csharp): priority queue comparer initialization (#1542)
Browse files Browse the repository at this point in the history
  • Loading branch information
hpstory authored Oct 31, 2024
1 parent 68a61f2 commit b3b10f2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions codes/csharp/chapter_heap/heap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public void Test() {
/* 初始化堆 */
// 初始化小顶堆
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("以下测试样例为大顶堆");

/* 元素入堆 */
Expand Down
4 changes: 2 additions & 2 deletions docs/chapter_heap/heap.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b3b10f2

Please sign in to comment.