diff --git a/codes/csharp/chapter_heap/heap.cs b/codes/csharp/chapter_heap/heap.cs index e822e0bb43..f50ceba3a8 100644 --- a/codes/csharp/chapter_heap/heap.cs +++ b/codes/csharp/chapter_heap/heap.cs @@ -24,8 +24,8 @@ public void Test() { /* 初始化堆 */ // 初始化小顶堆 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 d7ae9d2f0f..f4dd1d3485 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);