linked lists

BlitzMax Forums/BlitzMax Beginners Area/linked lists

Silly question (searched high and low and can't find anything), but does the built in linked list library have a way of getting the first and/or last member of the list? Something like

myList:TList = new Tlist

listAddLast myList, "one"
listAddLast myList, "two"
listAddLast myList, "three"

' I want to do something like

a$ = myList.first ' ie get the first member in the list

'or

a$ = myList.last ' ie get the first member in the list


I am trying to avoid stepping through the whole list with EachIn just to get the last member.

thanks,
Richard.

ahem!

nothing to see here, move along.

Oi! I told you to move along! So do it dammit!

Umm

TList.First()
TList.Last()

oops :)
I skimmed the source twice and missed them both times :)

Thanks Bot - just what I was after - couldn't find it in the docs anywhere.

Richard.

PS What about "tList.next()" and "tList.prev()"?

Now that *would* require you to extend the type (or manually access the _pred and _succ properties of the Link).

No extension needed, just usage of OO is needed as the none OO part does not contain this functionality ( which is why it isn't mentioned in the docs )

How could the Prevlink and Nextlink methods be used?
I still struggle with converting tlinks into something tangible.

with a TLink, you can typecast the _value field.
i.e. string(myTLink._value) for string

Can you please elaborate - how can I get the next/prev member of the tList.

many thanks,
Richard.

Local myList:TList = New TList
	myList.AddLast("test1")
	myList.AddLast("test2")
	myList.AddLast("test3")
	myList.AddLast("test4")
	myList.AddLast("test5")

Local current:TLink = myList.FirstLink()
Print String(current._value)
current = current._succ

While current <> myList._head
	Print String(current._value)
	current = current._succ
Wend 


Great! - many thanks,
Richard