首页 > 代码库 > 汉诺塔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
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。