首页 > 代码库 > 汉诺塔VB实现

汉诺塔VB实现

Dim num As Integer  '盘子的个数
Private Sub Hanoi(n As Integer, A As String, B As String, C As String) '移动盘子的递归过程    If n = 1 Then        Call Moves(A, C)    Else        Call Hanoi(n - 1, A, C, B)        Call Hanoi(1, A, B, C)        Call Hanoi(n - 1, B, A, C)    End IfEnd Sub
Private Sub Moves(A As String, B As String) '移动    Print A & "->" & B     '移动结果打印到屏幕上    List1.AddItem A & "->" & B  '移动结果输出到列表框中End Sub
Private Sub Command1_Click() '赋值及过程调用num = Val(Text1.Text)Call Hanoi(num, "A", "B", "C")End Sub