mirror of
https://github.com/krahets/hello-algo.git
synced 2024-12-27 00:16:30 +08:00
41 lines
682 B
Go
41 lines
682 B
Go
|
// File: hanota_test.go
|
||
|
// Created Time: 2023-07-21
|
||
|
// Author: hongyun-robot (1836017030@qq.com)
|
||
|
|
||
|
package chapter_divide_and_conquer
|
||
|
|
||
|
import (
|
||
|
"container/list"
|
||
|
"fmt"
|
||
|
"testing"
|
||
|
|
||
|
. "github.com/krahets/hello-algo/pkg"
|
||
|
)
|
||
|
|
||
|
func TestHanota(t *testing.T) {
|
||
|
// 串列尾部是柱子頂部
|
||
|
A := list.New()
|
||
|
for i := 5; i > 0; i-- {
|
||
|
A.PushBack(i)
|
||
|
}
|
||
|
B := list.New()
|
||
|
C := list.New()
|
||
|
fmt.Println("初始狀態下:")
|
||
|
fmt.Print("A = ")
|
||
|
PrintList(A)
|
||
|
fmt.Print("B = ")
|
||
|
PrintList(B)
|
||
|
fmt.Print("C = ")
|
||
|
PrintList(C)
|
||
|
|
||
|
solveHanota(A, B, C)
|
||
|
|
||
|
fmt.Println("圓盤移動完成後:")
|
||
|
fmt.Print("A = ")
|
||
|
PrintList(A)
|
||
|
fmt.Print("B = ")
|
||
|
PrintList(B)
|
||
|
fmt.Print("C = ")
|
||
|
PrintList(C)
|
||
|
}
|