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

@ -8,30 +8,30 @@ namespace hello_algo.chapter_computational_complexity;
public class space_complexity {
/* 函数 */
static int function() {
static int Function() {
// 执行某些操作
return 0;
}
/* 常数阶 */
static void constant(int n) {
static void Constant(int n) {
// 常量、变量、对象占用 O(1) 空间
int a = 0;
int b = 0;
int[] nums = new int[10000];
ListNode node = new ListNode(0);
ListNode node = new(0);
// 循环中的变量占用 O(1) 空间
for (int i = 0; i < n; i++) {
int c = 0;
}
// 循环中的函数占用 O(1) 空间
for (int i = 0; i < n; i++) {
function();
Function();
}
}
/* 线性阶 */
static void linear(int n) {
static void Linear(int n) {
// 长度为 n 的数组占用 O(n) 空间
int[] nums = new int[n];
// 长度为 n 的列表占用 O(n) 空间
@ -47,14 +47,14 @@ public class space_complexity {
}
/* 线性阶(递归实现) */
static void linearRecur(int n) {
static void LinearRecur(int n) {
Console.WriteLine("递归 n = " + n);
if (n == 1) return;
linearRecur(n - 1);
LinearRecur(n - 1);
}
/* 平方阶 */
static void quadratic(int n) {
static void Quadratic(int n) {
// 矩阵占用 O(n^2) 空间
int[,] numMatrix = new int[n, n];
// 二维列表占用 O(n^2) 空间
@ -69,19 +69,20 @@ public class space_complexity {
}
/* 平方阶(递归实现) */
static int quadraticRecur(int n) {
static int QuadraticRecur(int n) {
if (n <= 0) return 0;
int[] nums = new int[n];
Console.WriteLine("递归 n = " + n + " 中的 nums 长度 = " + nums.Length);
return quadraticRecur(n - 1);
return QuadraticRecur(n - 1);
}
/* 指数阶(建立满二叉树) */
static TreeNode? buildTree(int n) {
static TreeNode? BuildTree(int n) {
if (n == 0) return null;
TreeNode root = new TreeNode(0);
root.left = buildTree(n - 1);
root.right = buildTree(n - 1);
TreeNode root = new(0) {
left = BuildTree(n - 1),
right = BuildTree(n - 1)
};
return root;
}
@ -89,15 +90,15 @@ public class space_complexity {
public void Test() {
int n = 5;
// 常数阶
constant(n);
Constant(n);
// 线性阶
linear(n);
linearRecur(n);
Linear(n);
LinearRecur(n);
// 平方阶
quadratic(n);
quadraticRecur(n);
Quadratic(n);
QuadraticRecur(n);
// 指数阶
TreeNode? root = buildTree(n);
TreeNode? root = BuildTree(n);
PrintUtil.PrintTree(root);
}
}