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 If End 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
原文地址:http://blog.csdn.net/guoqingchun/article/details/27203591