用vb.net编程汉诺塔 vb汉诺塔程序

VB 程序设计 (汉诺塔问题)

给你个参考:

成都创新互联为客户提供专业的网站建设、做网站、程序、域名、空间一条龙服务,提供基于WEB的系统开发. 服务项目涵盖了网页设计、网站程序开发、WEB系统开发、微信二次开发、移动网站建设等网站方面业务。

Private Sub hanoi(n As Integer, one As String, two As String, three As String)

If n = 1 Then

Print Tab(5); one; "-------"; three

Else

Call hanoi(n - 1, one, three, two)

Print Tab(5); one; "-------"; three

Call hanoi(n - 1, two, one, three)

End If

End Sub

Private Sub Form_Click()

Dim x As Integer

x = Val(InputBox("请输入圆盘的个数"))

Print Tab(5); "将" x "个圆盘从A柱移到C柱的移动顺序为"

Call hanoi(x, "A", "B", "C")

End Sub

vb汉诺塔

private function Hnt(n as integer,A,as string,B as string,C as string)

Hnt (n-1),a,c,b

是上面的函数的四个参数呀,这是在函数中再次调用本函数

汉罗塔游戏VB程序怎么写

Dim N As Integer

Private Sub Form_Click()

Dim N As Integer

N = Val(InputBox("请输入汉诺塔的圆盘总数:"))

Call MoveDisk(N, "A", "B", "C")

End Sub

Sub MoveDisk(N, A As String, B As String, C As String)

If N = 1 Then

Print "将第1个圆盘从第" A "根柱子移到第" C "根柱子"

Else

Call MoveDisk(N - 1, A, C, B)

Print "将第" N "个圆盘从第" A "根柱子移到第" C "根柱子"

Call MoveDisk(N - 1, B, A, C)

End If

End Sub

这个是文字型的,你自己转换成图片的吧

VB:汉诺塔问题的递归调用函数

dim ncont as double

private function Hnt(n as integer,A,as string,B as string,C as string)

ncont=ncont+1

if n1 then

Hnt (n-1),a,c,b

Hnt (n-1),b,a,c

end if

end function

private sub command1_click()

dim i as integer

dim a as string

dim b as string

dim c as string

i=7 '此值即为汉诺塔的阶数.计算超过12的汉诺塔会死机,

Hnt (i,a,b,c)

text1.text=ncont

end sub

运行结果:127


分享标题:用vb.net编程汉诺塔 vb汉诺塔程序
文章链接:http://myzitong.com/article/doshsop.html