Results 1 to 3 of 3

Thread: [RESOLVED] Linked lists (beginners level)

  1. #1
    vbuggy krtxmrtz's Avatar
    Join Date
    May 02
    Location
    [41.5622N-2.0045E]
    Posts
    5,425

    Resolved [RESOLVED] Linked lists (beginners level)

    I was trying to get familiar with linked lists and found a very simple code snippet to get started:

    http://www.bigresource.com/VB-Linked...sPLfTJa4Q.html

    But the list I need must not have a beginning and an end, it must be cyclic, the last element must point to the first:

    Link 1 => Link 2 => Link 3 => ... => Link N => Link 1

    How do I implement this?
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  2. #2
    Hyperactive Member Lenggries's Avatar
    Join Date
    Sep 09
    Posts
    326

    Re: Linked lists (beginners level)

    In the example you linked to, you can forget about the CList class... it's completely unnecessary and only there for the comfort of that writer.

    Again, using the example of the code you linked to, this is all you need to do to close the loop of a linked list:

    Code:
    Private Sub CloseLinkedList(startNode As CLink)
       Dim node as CLink
    
       If Not (startNode Is Nothing)
          Set node = startNode
    
          'Iterate to the end of the linked lsit
          While Not (node.MyNext Is Nothing)
             Set node = node.MyNext
          Until 
    
          'Close the loop
          Set node.MyNext = startNode
       End If
    End Sub

  3. #3
    vbuggy krtxmrtz's Avatar
    Join Date
    May 02
    Location
    [41.5622N-2.0045E]
    Posts
    5,425

    Re: Linked lists (beginners level)

    Thank you, I must gradually get acquainted with this kind of structure I'd never used before. So I guess I may be back soon with more elementary questions.

    k

    Quote Originally Posted by Lenggries View Post
    In the example you linked to, you can forget about the CList class... it's completely unnecessary and only there for the comfort of that writer.

    Again, using the example of the code you linked to, this is all you need to do to close the loop of a linked list:

    Code:
    Private Sub CloseLinkedList(startNode As CLink)
       Dim node as CLink
    
       If Not (startNode Is Nothing)
          Set node = startNode
    
          'Iterate to the end of the linked lsit
          While Not (node.MyNext Is Nothing)
             Set node = node.MyNext
          Until 
    
          'Close the loop
          Set node.MyNext = startNode
       End If
    End Sub
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •