linear list of balls

BlitzMax Forums/BlitzMax Programming/linear list of balls

Robert Cummings(Posted 2005) [#1]
Hi...

Imagine a pearl necklace. Each ball knows the ball behind it and the ball in front of it.

I don't know how to do this with types. I thought I would need tlink but that might be more complicated than necessary?

Also I would need to put another ball in between other balls and update their links.

I'm almost ready to give up - I've searched the forum and still come away confused.

I appreciate any help you can give - thank you


Perturbatio(Posted 2005) [#2]
can't you just use a List?


TartanTangerine (was Indiepath)(Posted 2005) [#3]
Noooooooooooooooooooo he's doing a Puzz loop clone... Save us please.....

You need the Before and After Methods to do this.

		Method After:myType()
				Local link:TLink = ListFindLink(myType.myTlist,Self).NextLink()
				If link
					Return myType(link.Value())
				Else
					Return Null
				EndIf
		EndMethod
		
		'----------------------------------------------------------------
		
		Method Before:myType()
				Local link:TLink = ListFindLink(myType.myTlist,Self).PrevLink()
				If link
					Return myType(link.Value())
				Else
					Return Null
				EndIf
		EndMethod

Not sure if there is a InsertAfter function, too late again Hic!


Robert Cummings(Posted 2005) [#4]
lol...


TartanTangerine (was Indiepath)(Posted 2005) [#5]
Yeah there are the insert before and after methods.

Method InsertBeforeLink:TLink( value:Object,succ:TLink )
Inserts an object before the specified list link.

Method InsertAfterLink:TLink( value:Object,pred:TLink )
Inserts an object after the specified list link.


Robert Cummings(Posted 2005) [#6]
Thanks a lot, I understand before and after using links now I think - however I can't get those InsertBefore/after methods working. Do you have a quick working example of it's use?


Robert Cummings(Posted 2005) [#7]
Oops I have it, it's a list method...

[edit] no I've messed it up.


TartanTangerine (was Indiepath)(Posted 2005) [#8]
Function InsertAfter(list:TList,a:Object,b:Object)
	Local	link:TLink
	link=list.FindLink(a)
	list.InsertAfterLink(b,link)
End Function

Function InsertBefore((list:TList,a:Object,b:Object)
	Local	link:TLink
	link=list.FindLink(a)
	list.InsertBeforeLink(b,link)
End Function

t:TList=New TList
t.AddLast "A"
t.AddLast "B"

InsertAfter t,"B","C"

For a$=EachIn t
	Print a
Next



Robert Cummings(Posted 2005) [#9]
ah, thanks!