moving through a linked list
BlitzMax Forums/BlitzMax Beginners Area/moving through a linked list| 
 | ||
| i have been playing with lists and i am ok with the normal enumeration process, but i want to do something more along the lines of movenext, moveprevious, movefirst and movelast, has anyone any ideas on how i can do this | 
| 
 | ||
| Wrap TList in your own UDT. 
Type MyLinkedList Extends TList
    Field CurrentListItem:Object
... write your own movenext, moveprevious, etc functions
EndType
At least that's how I would do it in pretty much any other language. I'm admittedly a little light on BMax knowledge currently as I took more than a few years away from it and only recently am returning. | 
| 
 | ||
| thanks Kanati, had a think and i recon i need to look at tlink objects, so my next question is how do i get the first link in the list, so i can do the (object=Tlist.value()) to pull the first object in the list | 
| 
 | ||
| to access the first linked item in the list: myLink = myList.FirstLink() the last link: myLink = MyList.LastLink() the next link: myLink = myLink.NextLink() the previous link: myLink = myLink.PrevLink() to get the object of the link: car = Tcar(link.Value()) if you are in the first link and try to access the previous link it will return a null so treat accordingly. same thing with either of the methods above. | 
| 
 | ||
| you have been a great help Jesse, many thanks! |