Getting the first or last object in a list

BlitzMax Forums/BlitzMax Beginners Area/Getting the first or last object in a list

po(Posted 2007) [#1]
If I had a list of objects, what would be a simple way of getting the first one in the list? And the last one?

-Thanks


H&K(Posted 2007) [#2]
Store those two links.

But remember if you sort the list it will change, and then you will probably have to store the first link, then scan though and find the last link

Listaddlast, get that link, find what is linked to, then delete the first one (the one you just added)
ListaddFirst, get that link, find what is linked to, then delete the first one (the one you just added)


WendellM(Posted 2007) [#3]
Methods First and Last (for objects) and FirstLink and LastLink (for links) also do the job:
foo:TList = New TList

ListAddLast foo, "first"
ListAddLast foo, "second"
ListAddLast foo, "third"

Print String( foo.First() )
Print String( foo.Last() )



po(Posted 2007) [#4]
Great, thanks.