Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim fileContents As String
fileContents = My.Computer.FileSystem.ReadAllText(Application.StartupPath & "\dfs.txt")
Dim lines = fileContents.Trim().Split(vbNewLine)
Dim gdict As New Dictionary(Of String, Array)
For i = 0 To lines.Length - 1
Dim cols = lines(i).Split(":")
Dim sep = {Chr(34), Chr(39), " ", "[", "]", ","}
Dim nod = cols(0).Trim().Split(sep, StringSplitOptions.RemoveEmptyEntries)
Dim cnod = cols(1).Split(sep, StringSplitOptions.RemoveEmptyEntries)
gdict.Add(nod(0), cnod)
Next
dfs(visited, gdict, "5")
MsgBox(ss)
End Sub
Dim visited As New ArrayList
Dim ss = ""
Sub dfs(ByRef visited, ByRef graph, ByVal nod)
If Not visited.contains(nod) Then
ss = ss & nod & " "
visited.add(nod)
For Each neighbor In graph(nod)
dfs(visited, graph, neighbor)
Next
End If
End Sub
End Class
沒有留言:
張貼留言