From a8797d8be0bb09d39202c3bd8852243b3f593918 Mon Sep 17 00:00:00 2001 From: hpstory <354195783@qq.com> Date: Thu, 31 Oct 2024 15:40:59 +0800 Subject: [PATCH] fix(csharp): priority queue comparer initialization --- 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 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);