borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Previous Topic (Master VB.NET And Get your MCP NOW!!!)Next Topic (Visual Studio 2005) New Topic New Poll Post Reply
AndreaVB Forum : VB.Net : Problem with Traversal
Poster Message
Falzzzz
Level: Trainee

Registered: 05-03-2006
Posts: 1

icon 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
View Profile Send Email to User Show All Posts | Quote Reply
stickleprojects
Level: Moderator


Registered: 09-09-2002
Posts: 891
icon Re: Problem with Traversal

Hi,
sorry for the delay.
This is a single-linked nodelist, so you need to reset the pointer of the previous node to the next one.
as in:

Dim cnode As clsNode
dim prevnode as clsNode
        For Each cnode In myRoute.myRoutes
            if cnode.Data.mCountry=strDatatoDelete then
                  if not prevnode is nothing then
                    prevnode.NLink = cnode.NLink
                   end if
                     cnode = null
            else
                    myRoute.search_remove(cnode)

            End If
            prevnode = cnode
        Next


Hope this helps,
Kieron


____________________________
Build it better, faster, quicker, easier.. then fix it (non-offical MS mission statement)

04-06-2006 at 10:37 PM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VB.Net : Problem with Traversal
Previous Topic (Master VB.NET And Get your MCP NOW!!!)Next Topic (Visual Studio 2005) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2007 Andrea Tincaniborder