linear list of balls
BlitzMax Forums/BlitzMax Programming/linear list of balls
| ||
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 |
| ||
can't you just use a List? |
| ||
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! |
| ||
lol... |
| ||
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. |
| ||
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? |
| ||
Oops I have it, it's a list method... [edit] no I've messed it up. |
| ||
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 |
| ||
ah, thanks! |