PrevLink() & NextLink()

BlitzMax Forums/BlitzMax Programming/PrevLink() & NextLink()

TartanTangerine (was Indiepath)(Posted 2005) [#1]
Help again, please..

I have my list which I am looping through
For g:myGUI = EachIn myGUITList
   BLAH
Next

If a certain condition is met in "BLAH" then I want to be able to get/set a variable in either the Previous or Next Link

How do I use those commands?


FlameDuck(Posted 2005) [#2]
How do I use those commands?
You can't, when you're using eachin, since eachin gives you the actual object (aka. value) in question, rather than the TLink.


tonyg(Posted 2005) [#3]
I've answered on CW but here's a clumsy example...
my_list:TList=CreateList()    
Type my_type  
  Field my_num                
End Type
For x = 5 To 11                
  f:my_Type = New my_Type
  f.my_num=x
  ListAddLast my_list,f
Next
currentLink:TLink=my_list.firstlink() 
Repeat 
	currenttype:my_type = my_type(currentlink.value())     
	If currenttype.my_num=9      ' This is the value/field you're looking for. 
		my_next_link:TLink=currentlink.nextlink()
		my_prev_link:TLink=currentlink.prevlink()
	    my_next_type:my_type = my_type(my_next_link.value())
	    my_next_type.my_num=999
	    my_prev_type:my_type = my_type(my_prev_link.value())
	    my_prev_type.my_num=888
	    currentlink:TLink=currentlink.nextlink()
	Else
	    currentlink:TLink=currentlink.nextlink()
	EndIf
Until currentlink=Null

For a:my_type =  EachIn my_list
   Print a.my_num
Next

You'll need to add checks whether my_next_link and my_prev_link are null to avoid errors.
If anybody can clean this up I'd appreciate it.


Bot Builder(Posted 2005) [#4]
I'm working on a totally restructured and rewritten version of TList (Group and node rather than TList and TLink). Also included is a LIFO (last in first out) stack that is used for for/eachin loops so that you can get the current node object for nested loops.

I've got alot of it working, but still yet to finish all the functions, document and test them. It will also be much more hierarchy friendly. Groups extend nodes so they can be used as the nodes of other groups.

The main problem i'm trying to deal with now is that if you exit a for eachin loop withour letting it finish, it never gets popped off the enums stack. Not a major problem, but if you have code right after that relys on getting the handle of the current node for the parent loop, you'll accidently access the loop from before. Also it wastes memory.

I'm going to post a request thread so that a method is called when exiting the enumerator.

I had a modification of the linkedlists module that allowed TLink access during looping. The problem was i was also trying to edit the list using this and ended up messing up the link structure so that it wouldnt iterate right. My hierarchy lib will have lots of convenience functions to help with this kind of thing.


Yan(Posted 2005) [#5]
Am I missing something?


Or




Bot Builder(Posted 2005) [#6]
I think we mean a faster way. Although #2 is decent speed, The added work would be annoiying. imagine #1 with a lis of 10000 objects - very slow.


TartanTangerine (was Indiepath)(Posted 2005) [#7]
Thank you people, I can get on with my work now :D