Question about TList.Reverse Command.

BlitzMax Forums/BlitzMax Programming/Question about TList.Reverse Command.

TList is a doubly linked list: each link contains a reference to the previous link as well as the next link (and of course the value for that cell). The first link's PrevLink is null, the last link's NextLink is null. All you have to do is walk through from the list's LastLink to it's FirstLink.

SuperStrict
Local mylist:TList=CreateList()
mylist.addlast("one")
mylist.addlast("two")
mylist.addlast("three")
mylist.addlast("four")
mylist.addlast("five")
Print "*** BACKWARD - NO EXTRA WORK ***"
If Not mylist.IsEmpty()					' The loop will cause an error if you run it on an empty list
	Local link:TLink = mylist.LastLink()	' Get the last link
	Repeat
		Print String(link.Value())		' Value() returns the object corresponding to this link
		link = link.PrevLink()			' If PrevLink() returns null, then we are at the first link
	Until link = Null					' So stop looping
EndIf