Getting the first or last object in a list
BlitzMax Forums/BlitzMax Beginners Area/Getting the first or last object in a list
| ||
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 |
| ||
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) |
| ||
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() ) |
| ||
Great, thanks. |