result(1, result1) = ll
result(2, result1) = s1
GoTo 300
Else
GoTo 300
End If
End If
ycd(result1) = True
rs1(result1) = s1
result(1, result1) = ll
result(2, result1) = s1
j = j + 1
ReDim Preserve no(1 To j) As Integer
no(j) = result1
300 Next I
设置最小为无穷大,最短路径点为空
min = 1E+38
minpoint = Null
(优化部分)
找出已经查过点中长度最短的点
For I = aa To j
If min > rs1(no(i)) Then
ii = I
min = rs1(no(i))
minpoint = no(i)
End If
Next I
如果没有结果,即起点与终点没有通路退出程序
If min = 1E+38 Then Exit Function
(重点优化)将两点互换,减少循环。
No(ii) = no(aa)
no(aa) = minpoint
标记已经作为结果点判断过
yc(minpoint) = True
ll = minpoint
判断结果点是否等于终点,如果等于则已经找到最短路径
If minpoint = endno Then Exit For
Next aa
返回最短路径长度
Stpath = result(2, endno)
End Function
-----------------------------------------------------------------------------------------
最短路径程序
Option Explicit
Dim p(7) As rcd
Dim Matrix(7, 7) As Integer
Private Sub Command2_Click()
End
End Sub
Function seekSmall(a() As Integer)
Dim n, k, m, i, j As Integer
n = UBound(a) - 2
i = 1
m = a(0, 1): k = 0
Do While a(i, 1) <> 0
If a(i, 1) < m Then
m = a(i, 1): k = i
End If
i = i + 1
Loop
seekSmall = k
Print
End Function
Private Sub cmdContinue_Click()
MsgBox "请输入要求的路径", vbOKCancel
txtStart.Text = "": txtEnd.Text = "": txtStart.SetFocus
txtPath.Text = "": txtLength.Text = ""
End Sub
Private Sub cmdEnd_Click()
End
End Sub
Private Sub cmdOk_Click()
Dim nS, nE As Integer
Dim h As String
Dim i, j As Integer
Dim n As Integer
Dim x, y, z As Integer
If txtStart.Text <> "" And txtEnd.Text <> "" Then
nS = Val(txtStart.Text) - 1: n






