Private Sub Command1_Click()
Dim m As Integer
List1.Clear
m = Val(Text1.Text)
Call hanoi(m, "a", "b", "c")
End Sub
Sub hmove(getone As String, putone As String)
Dim temp As String
temp = getone & "===>" & putone & " "
List1.AddItem temp
End Sub
1. Sub hanoi(n As Integer, one As String, two As String, three As String)
2. If n = 1 Then
3. Call hmove(one, three)
4. Else
5. Call hanoi(n - 1, one, three, two)
6. Call hmove(one, three)
7. Call hanoi(n - 1, two, one, three)
8. End If
9. End Sub
当n的值为3,传入1时,执行2、4、5后又回到1,这样当n的值为1时跳到过程 hmove .执行完hmove后跳到8、9
执行,为什么当执行完8、9时n的值会自动加1?为什么还会马上跳回到6执行?当执行完6程序从homve过程中跳回
时执行7,重新又回到1、2、3开始执行跳到hmove过程后回来执行7,程序跳到1、2、3、hmove过程,完了后为什么
一直在8、9(end if ;end sub)之间执行,每执行一次n就加1,当n=3时又跳到6重新执行(好像程序又进入新的循环)???为什么会这样跳来跳去的???到底这程序在按照什么来跳???
[此贴子已经被作者于2005-12-27 17:25:20编辑过]