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

@@ -18,7 +18,7 @@ class Pair {
/* 基于数组简易实现的哈希表 */
class ArrayHashMap {
private List<Pair?> buckets;
private readonly List<Pair?> buckets;
public ArrayHashMap() {
// 初始化数组,包含 100 个桶
buckets = new();
@@ -28,35 +28,35 @@ class ArrayHashMap {
}
/* 哈希函数 */
private int hashFunc(int key) {
private int HashFunc(int key) {
int index = key % 100;
return index;
}
/* 查询操作 */
public string? get(int key) {
int index = hashFunc(key);
public string? Get(int key) {
int index = HashFunc(key);
Pair? pair = buckets[index];
if (pair == null) return null;
return pair.val;
}
/* 添加操作 */
public void put(int key, string val) {
Pair pair = new Pair(key, val);
int index = hashFunc(key);
public void Put(int key, string val) {
Pair pair = new(key, val);
int index = HashFunc(key);
buckets[index] = pair;
}
/* 删除操作 */
public void remove(int key) {
int index = hashFunc(key);
public void Remove(int key) {
int index = HashFunc(key);
// 置为 null ,代表删除
buckets[index] = null;
}
/* 获取所有键值对 */
public List<Pair> pairSet() {
public List<Pair> PairSet() {
List<Pair> pairSet = new();
foreach (Pair? pair in buckets) {
if (pair != null)
@@ -66,7 +66,7 @@ class ArrayHashMap {
}
/* 获取所有键 */
public List<int> keySet() {
public List<int> KeySet() {
List<int> keySet = new();
foreach (Pair? pair in buckets) {
if (pair != null)
@@ -76,7 +76,7 @@ class ArrayHashMap {
}
/* 获取所有值 */
public List<string> valueSet() {
public List<string> ValueSet() {
List<string> valueSet = new();
foreach (Pair? pair in buckets) {
if (pair != null)
@@ -86,8 +86,8 @@ class ArrayHashMap {
}
/* 打印哈希表 */
public void print() {
foreach (Pair kv in pairSet()) {
public void Print() {
foreach (Pair kv in PairSet()) {
Console.WriteLine(kv.key + " -> " + kv.val);
}
}
@@ -98,40 +98,40 @@ public class array_hash_map {
[Test]
public void Test() {
/* 初始化哈希表 */
ArrayHashMap map = new ArrayHashMap();
ArrayHashMap map = new();
/* 添加操作 */
// 在哈希表中添加键值对 (key, value)
map.put(12836, "小哈");
map.put(15937, "小啰");
map.put(16750, "小算");
map.put(13276, "小法");
map.put(10583, "小鸭");
map.Put(12836, "小哈");
map.Put(15937, "小啰");
map.Put(16750, "小算");
map.Put(13276, "小法");
map.Put(10583, "小鸭");
Console.WriteLine("\n添加完成后哈希表为\nKey -> Value");
map.print();
map.Print();
/* 查询操作 */
// 向哈希表输入键 key ,得到值 value
string? name = map.get(15937);
string? name = map.Get(15937);
Console.WriteLine("\n输入学号 15937 ,查询到姓名 " + name);
/* 删除操作 */
// 在哈希表中删除键值对 (key, value)
map.remove(10583);
map.Remove(10583);
Console.WriteLine("\n删除 10583 后,哈希表为\nKey -> Value");
map.print();
map.Print();
/* 遍历哈希表 */
Console.WriteLine("\n遍历键值对 Key->Value");
foreach (Pair kv in map.pairSet()) {
foreach (Pair kv in map.PairSet()) {
Console.WriteLine(kv.key + " -> " + kv.val);
}
Console.WriteLine("\n单独遍历键 Key");
foreach (int key in map.keySet()) {
foreach (int key in map.KeySet()) {
Console.WriteLine(key);
}
Console.WriteLine("\n单独遍历值 Value");
foreach (string val in map.valueSet()) {
foreach (string val in map.ValueSet()) {
Console.WriteLine(val);
}
}