前端之家收集整理的这篇文章主要介绍了
汉诺塔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,B,C)
Call Hanoi(n - 1,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
原文链接:https://www.f2er.com/vb/258032.html