From b3b10f230050c4b9291bd98956cb985427806407 Mon Sep 17 00:00:00 2001 From: hpstory <33348162+hpstory@users.noreply.github.com> Date: Thu, 31 Oct 2024 21:25:32 +0800 Subject: [PATCH] fix(csharp): priority queue comparer initialization (#1542) --- codes/csharp/chapter_heap/heap.cs | 4 ++-- docs/chapter_heap/heap.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/codes/csharp/chapter_heap/heap.cs b/codes/csharp/chapter_heap/heap.cs index e822e0bb4..f50ceba3a 100644 --- a/codes/csharp/chapter_heap/heap.cs +++ b/codes/csharp/chapter_heap/heap.cs @@ -24,8 +24,8 @@ public class heap { /* 初始化堆 */ // 初始化小顶堆 PriorityQueue minHeap = new(); - // 初始化大顶堆(使用 lambda 表达式修改 Comparator 即可) - PriorityQueue maxHeap = new(Comparer.Create((x, y) => y - x)); + // 初始化大顶堆(使用 lambda 表达式修改 Comparer 即可) + PriorityQueue maxHeap = new(Comparer.Create((x, y) => y.CompareTo(x))); Console.WriteLine("以下测试样例为大顶堆"); /* 元素入堆 */ diff --git a/docs/chapter_heap/heap.md b/docs/chapter_heap/heap.md index d7ae9d2f0..f4dd1d348 100644 --- a/docs/chapter_heap/heap.md +++ b/docs/chapter_heap/heap.md @@ -157,8 +157,8 @@ /* 初始化堆 */ // 初始化小顶堆 PriorityQueue minHeap = new(); - // 初始化大顶堆(使用 lambda 表达式修改 Comparator 即可) - PriorityQueue maxHeap = new(Comparer.Create((x, y) => y - x)); + // 初始化大顶堆(使用 lambda 表达式修改 Comparer 即可) + PriorityQueue maxHeap = new(Comparer.Create((x, y) => y.CompareTo(x))); /* 元素入堆 */ maxHeap.Enqueue(1, 1);