mirror of
https://github.com/krahets/hello-algo.git
synced 2026-08-12 20:00:58 +00:00
Format C, C++, C#, Go, Java, Python, Rust code.
This commit is contained in:
@@ -6,8 +6,9 @@ package chapter_divide_and_conquer
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
. "github.com/krahets/hello-algo/pkg"
|
||||
"testing"
|
||||
|
||||
. "github.com/krahets/hello-algo/pkg"
|
||||
)
|
||||
|
||||
func TestBuildTree(t *testing.T) {
|
||||
|
||||
@@ -32,7 +32,7 @@ func dfsHanota(i int, src, buf, tar *list.List) {
|
||||
}
|
||||
|
||||
/* 求解汉诺塔 */
|
||||
func hanota(A, B, C *list.List) {
|
||||
func solveHanota(A, B, C *list.List) {
|
||||
n := A.Len()
|
||||
// 将 A 顶部 n 个圆盘借助 B 移到 C
|
||||
dfsHanota(n, A, B, C)
|
||||
|
||||
@@ -7,8 +7,9 @@ package chapter_divide_and_conquer
|
||||
import (
|
||||
"container/list"
|
||||
"fmt"
|
||||
. "github.com/krahets/hello-algo/pkg"
|
||||
"testing"
|
||||
|
||||
. "github.com/krahets/hello-algo/pkg"
|
||||
)
|
||||
|
||||
func TestHanota(t *testing.T) {
|
||||
@@ -27,7 +28,7 @@ func TestHanota(t *testing.T) {
|
||||
fmt.Print("C = ")
|
||||
PrintList(C)
|
||||
|
||||
hanota(A, B, C)
|
||||
solveHanota(A, B, C)
|
||||
|
||||
fmt.Println("圆盘移动完成后:")
|
||||
fmt.Print("A = ")
|
||||
|
||||
Reference in New Issue
Block a user