|
-
Jul 2nd, 2012, 03:05 PM
#1
[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)
-
Jul 2nd, 2012, 04:33 PM
#2
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
-
Jul 3rd, 2012, 10:16 AM
#3
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
 Originally Posted by Lenggries
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|