easy way to change object position in list?

BlitzMax Forums/BlitzMax Programming/easy way to change object position in list?

Robert Cummings(Posted 2005) [#1]
Hi all,

I want to change the order of objects in my linked list. Is there a really easy way of doing this?


Perturbatio(Posted 2005) [#2]
You could manually modify the _succ and _pred Fields of the TLink


Robert Cummings(Posted 2005) [#3]
How would I do this? sorry I'm not very experienced in bmax yet.


Perturbatio(Posted 2005) [#4]
I was thinking on it and you don't really need to mess around with the _pred and _succ fields at all. Just the value




Tom(Posted 2005) [#5]
how about...




Robert Cummings(Posted 2005) [#6]
Thanks lads that looks great :)

SwapLinks looks good. How do I find the current link? I saw a command called FindLink but I am not sure how to use it. Ideally I'd use this function:

Function SwapLinks(Link1:TLink, Link2:TLink)
	Local tempVal:Object
	tempVal = Link1._value
	
	Link1._value = Link2._value
	Link2._value = tempVal
End Function


And just pass the two links in and it should work? Or am I way off base?


Perturbatio(Posted 2005) [#7]
And just pass the two links in and it should work? Or am I way off base?


That's pretty much how you would use it.

The problem with using findlink is that you need to have a variable that points to the object you want to find in the first place.

The easiest way to do it is as I have in SwapNums, that is, loop through the list and compare each TLinks until you find the ones you need.