Const n=8 Dim a(1 To n) As Integer,b(1 To n) As Integer Private Sub Form_Load ( ?。?br />‘隨機(jī)產(chǎn)生n個[1,20]之間的不重復(fù)的正整數(shù),并在list1中顯示具體代碼略 End Sub Private Sub Command1_Click ( ?。?br />Dim i As Integer,j As Integer,t As Integer,p as integer,p as integer For i=1 To n-1 For j=n To i+1 Step-1 If a(j)<a(j-1)Then t=a(j):a(j)=a(j-1):a(j-1)=t end If Next j Next i p=n:(1) For i=1 To n Step 2 (2) b(i+1)=a(q) p=p-2 q=q+1 Next i For i=1 To n List2.AddItem Str(b(i)) Next i End Sub
Dim a(1 To 50)As Integer Private Sub Command1_Click ( ) Dim i As Integer,j As Integer,pos As Integer Dim cha(1 To 10)As Integer'記錄一條線路中各個岔路口坐標(biāo) Dim lu(1 To 10)As Integer'記錄路線經(jīng)過的坐標(biāo) pos=1:j=0:lu(1)=1:i=1 Do While i<=9‘第1個和最后1個固定,中間有9個需要路過的坐標(biāo) If pos Mod 6<>0 And a(zb+1)=1 Then'向右暢通 If pos+6<=30 and a(zb+6)=1 Then‘記錄岔路口 j=j+1 ①
End If pos=pos+1 i=i+1 ②
ElseIf pos+6<=30 And a(pos+6)=1 Then'向下暢通 pos=pos+6 i=i+1 lu(i)=pos Else'坐標(biāo)退回到上一個岔路口 If j=0 Then Exit Do Do While lu(i)<>cha(j) ③
Loop a(cha(j)+1)=0’標(biāo)記此路口右側(cè)不可用 pos=cha(j) j=j-1 End If Loop If j=0 Then Text1.Text=“沒有暢通道路“ Else For i=1 To 10 Text1.Text=Text1.Text+Str(lu(i)) Next i End If End Sub