fix(csharp): Modify method name to PascalCase, simplify new expression (#840)

* Modify method name to PascalCase(array and linked list)

* Modify method name to PascalCase(backtracking)

* Modify method name to PascalCase(computational complexity)

* Modify method name to PascalCase(divide and conquer)

* Modify method name to PascalCase(dynamic programming)

* Modify method name to PascalCase(graph)

* Modify method name to PascalCase(greedy)

* Modify method name to PascalCase(hashing)

* Modify method name to PascalCase(heap)

* Modify method name to PascalCase(searching)

* Modify method name to PascalCase(sorting)

* Modify method name to PascalCase(stack and queue)

* Modify method name to PascalCase(tree)

* local check
This commit is contained in:
hpstory
2023-10-08 01:33:46 +08:00
committed by GitHub
parent 6f7e768cb7
commit f62256bee1
129 changed files with 1186 additions and 1192 deletions

View File

@@ -7,32 +7,33 @@
namespace hello_algo.chapter_heap;
public class heap {
public void testPush(PriorityQueue<int, int> heap, int val) {
public void TestPush(PriorityQueue<int, int> heap, int val) {
heap.Enqueue(val, val); // 元素入堆
Console.WriteLine($"\n元素 {val} 入堆后\n");
PrintUtil.PrintHeap(heap);
}
public void testPop(PriorityQueue<int, int> heap) {
public void TestPop(PriorityQueue<int, int> heap) {
int val = heap.Dequeue(); // 堆顶元素出堆
Console.WriteLine($"\n堆顶元素 {val} 出堆后\n");
PrintUtil.PrintHeap(heap);
}
[Test]
public void Test() {
/* 初始化堆 */
// 初始化小顶堆
PriorityQueue<int, int> minHeap = new PriorityQueue<int, int>();
PriorityQueue<int, int> minHeap = new();
// 初始化大顶堆(使用 lambda 表达式修改 Comparator 即可)
PriorityQueue<int, int> maxHeap = new PriorityQueue<int, int>(Comparer<int>.Create((x, y) => y - x));
PriorityQueue<int, int> maxHeap = new(Comparer<int>.Create((x, y) => y - x));
Console.WriteLine("以下测试样例为大顶堆");
/* 元素入堆 */
testPush(maxHeap, 1);
testPush(maxHeap, 3);
testPush(maxHeap, 2);
testPush(maxHeap, 5);
testPush(maxHeap, 4);
TestPush(maxHeap, 1);
TestPush(maxHeap, 3);
TestPush(maxHeap, 2);
TestPush(maxHeap, 5);
TestPush(maxHeap, 4);
/* 获取堆顶元素 */
int peek = maxHeap.Peek();
@@ -40,11 +41,11 @@ public class heap {
/* 堆顶元素出堆 */
// 出堆元素会形成一个从大到小的序列
testPop(maxHeap);
testPop(maxHeap);
testPop(maxHeap);
testPop(maxHeap);
testPop(maxHeap);
TestPop(maxHeap);
TestPop(maxHeap);
TestPop(maxHeap);
TestPop(maxHeap);
TestPop(maxHeap);
/* 获取堆大小 */
int size = maxHeap.Count;