mirror of
https://github.com/krahets/hello-algo.git
synced 2026-05-11 11:07:14 +08:00
feat(csharp) .NET 8.0 code migration (#966)
* .net 8.0 migration * update docs * revert change * revert change and update appendix docs * remove static * Update binary_search_insertion.cs * Update binary_search_insertion.cs * Update binary_search_edge.cs * Update binary_search_insertion.cs * Update binary_search_edge.cs --------- Co-authored-by: Yudong Jin <krahets@163.com>
This commit is contained in:
@@ -8,7 +8,7 @@ namespace hello_algo.chapter_divide_and_conquer;
|
||||
|
||||
public class hanota {
|
||||
/* 移动一个圆盘 */
|
||||
public void Move(List<int> src, List<int> tar) {
|
||||
void Move(List<int> src, List<int> tar) {
|
||||
// 从 src 顶部拿出一个圆盘
|
||||
int pan = src[^1];
|
||||
src.RemoveAt(src.Count - 1);
|
||||
@@ -17,7 +17,7 @@ public class hanota {
|
||||
}
|
||||
|
||||
/* 求解汉诺塔:问题 f(i) */
|
||||
public void DFS(int i, List<int> src, List<int> buf, List<int> tar) {
|
||||
void DFS(int i, List<int> src, List<int> buf, List<int> tar) {
|
||||
// 若 src 只剩下一个圆盘,则直接将其移到 tar
|
||||
if (i == 1) {
|
||||
Move(src, tar);
|
||||
@@ -32,7 +32,7 @@ public class hanota {
|
||||
}
|
||||
|
||||
/* 求解汉诺塔 */
|
||||
public void SolveHanota(List<int> A, List<int> B, List<int> C) {
|
||||
void SolveHanota(List<int> A, List<int> B, List<int> C) {
|
||||
int n = A.Count;
|
||||
// 将 A 顶部 n 个圆盘借助 B 移到 C
|
||||
DFS(n, A, B, C);
|
||||
@@ -41,9 +41,9 @@ public class hanota {
|
||||
[Test]
|
||||
public void Test() {
|
||||
// 列表尾部是柱子顶部
|
||||
List<int> A = new() { 5, 4, 3, 2, 1 };
|
||||
List<int> B = new();
|
||||
List<int> C = new();
|
||||
List<int> A = [5, 4, 3, 2, 1];
|
||||
List<int> B = [];
|
||||
List<int> C = [];
|
||||
Console.WriteLine("初始状态下:");
|
||||
Console.WriteLine("A = " + string.Join(", ", A));
|
||||
Console.WriteLine("B = " + string.Join(", ", B));
|
||||
|
||||
Reference in New Issue
Block a user