fix(csharp): priority queue comparer initialization (#1542)

This commit is contained in:
hpstory 2024-10-31 21:25:32 +08:00 committed by GitHub
parent 68a61f23d5
commit b3b10f2300
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 4 deletions

View file

@ -24,8 +24,8 @@ public class heap {
/* 初始化堆 */ /* 初始化堆 */
// 初始化小顶堆 // 初始化小顶堆
PriorityQueue<int, int> minHeap = new(); PriorityQueue<int, int> minHeap = new();
// 初始化大顶堆(使用 lambda 表达式修改 Comparator 即可) // 初始化大顶堆(使用 lambda 表达式修改 Comparer 即可)
PriorityQueue<int, int> maxHeap = new(Comparer<int>.Create((x, y) => y - x)); PriorityQueue<int, int> maxHeap = new(Comparer<int>.Create((x, y) => y.CompareTo(x)));
Console.WriteLine("以下测试样例为大顶堆"); Console.WriteLine("以下测试样例为大顶堆");
/* 元素入堆 */ /* 元素入堆 */

View file

@ -157,8 +157,8 @@
/* 初始化堆 */ /* 初始化堆 */
// 初始化小顶堆 // 初始化小顶堆
PriorityQueue<int, int> minHeap = new(); PriorityQueue<int, int> minHeap = new();
// 初始化大顶堆(使用 lambda 表达式修改 Comparator 即可) // 初始化大顶堆(使用 lambda 表达式修改 Comparer 即可)
PriorityQueue<int, int> maxHeap = new(Comparer<int>.Create((x, y) => y - x)); PriorityQueue<int, int> maxHeap = new(Comparer<int>.Create((x, y) => y.CompareTo(x)));
/* 元素入堆 */ /* 元素入堆 */
maxHeap.Enqueue(1, 1); maxHeap.Enqueue(1, 1);