Linked List for Visual Basic

  • 13 years ago

    How do you write code to implement a linked list?

  • 13 years ago
    Hi this is wikram,

    well buddy as u must be nowing that in a linked list ther are two fields one for data and other for the address of the second iteh of the linked list the variable in which u store the addres of the next is a pointer variable and pointers are not provided by VB. so i guess that u cant implement a linked list in VB try using arrays instead
  • 13 years ago

    Actually, it is possible to implement a Linked List in VB by using Classes.  Simply have a property that is of the Class type and use it as the Next pointer.

    '::: Class Declaration
    Public Class LLClass
     Dim NextEntry As LLClass
     Public Sub ClassInitialize()
       Set NextEntry = Nothing
     End Sub
     Public Sub Class
       Set NextEntry = Nothing
     End Sub
    End Class

    '::: Code
    Dim FirstEntry As LLClass
    Dim temp As LLClass
    Dim temp2 as LLClass

    Set FirstEntry = New LLClass
    Set temp = New LLClass

    '::: increase the linked list
    Set FirstEntry.NextEntry = temp

    '::: add another
    Set temp = New LLClass
    Set FirstEntry.NextEntry.NextEntry = temp
    '::: or...
    Set temp2 = FirstEntry.NextEntry
    Set temp2.NextEntry = temp

    '::: Loop through the list
    Set temp = FirstEntry
    Do While Not (temp Is Nothing)
     '::: operate against the LL entry
     Set temp = temp.NextEntry

    '::: Done

    This is untested code, but it should work just fine.

Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Anyone who considers arithmetic methods of producing random digits is, of course, in a state of sin.” - John von Neumann