 |
|
 |
Falzzzz Level: Trainee
 Registered: 05-03-2006 Posts: 1
|
Problem with Traversal
Hi guys, im new here and kinda new to vb too though this seems like a helpful community so i thought i might share my problem and get some help or hints as to fixing it. Im having some problem when it comes to delete a node from the linked list structure i have created. The only solution i can figure out until now is to specify the headnode of the linked list and it will remove the last link in that list.
Im trying to let the user delete any specific node he requires.
The code below might give a better explanation or show you what i have reached so far.
clsNode (Class)
Public NLink As clsNode
Public Data As New clsRoute
|
clsRoute (Class)
Public myRoutes As New Collection
Public mCountry As String
Public mCity As String
Public Function AddNode(ByVal City As String, ByVal Country As String, ByVal blnStart As Boolean)
If blnStart Then
Dim ln As New clsNode
ln.Data.mCity = City
ln.Data.mCountry = Country
myRoutes.Add(ln)
Else
Traverse(myRoutes.Item(myRoutes.Count), City, Country)
End If
End Function
Public Sub Traverse(ByVal lnode As clsNode, ByVal City As String, ByVal Country As String)
If lnode.NLink Is Nothing Then
Dim ln As New clsNode
ln.Data.mCity = City
ln.Data.mCountry = Country
lnode.NLink = ln
Else
Traverse(lnode.NLink, City, Country)
End If
End Sub
Public Sub TraversDisplay(ByVal lnode As clsNode)
If lnode Is Nothing Then
Exit Sub
Else
TraversDisplay(lnode.NLink)
End If
End Sub
Public Sub search_remove(ByVal lnode As clsNode)
If lnode.NLink.NLink Is Nothing Then
lnode.NLink = Nothing
Else
search_remove(lnode.NLink)
End If
End Sub
|
Adding Head Nodes
myRoute.AddNode(txtCity.Text, txtCountry.Text, True)
|
Adding Link
myRoute.AddNode(txtCity.Text, txtCountry.Text, False)
|
Delete Code
Dim cnode As clsNode
For Each cnode In myRoute.myRoutes
If (cnode.Data.mCountry = txtCountry.Text) Then
If cnode.NLink.NLink Is Nothing Then
cnode.NLink = Nothing
Else
myRoute.search_remove(cnode)
End If
End If
Next
|
Many thanks guys, i would appreciate some help or pointful hints/tips as to how i can go around solving the problem as im still new to vb.net
|
|
06-03-2006 at 04:32 PM |
|
|
|
|
 |
 |