easy way to change object position in list?

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

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

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

Type TItem
	Field val:Int
End Type

Global myList:Tlist = New TList
Global i:Int
Global tempItem:TItem

For i = 0 To 10
	tempItem = New TItem
		tempItem.val = i
	myList.AddLast(tempItem)
Next

Print "First sequence"
Print
'Print items in sequence
For tempItem = EachIn myList
	Print tempItem.val
Next
Print
Print "Swapping"
Print
swapnums(3,7)

Print "Second Sequence"
Print
'Print items in sequence
For tempItem = EachIn myList
	Print tempItem.val
Next


Function swapnums(num1, num2)
	Local currentLink:TLink
	Local Link1:TLink
	Local Link2:TLink
	
	currentLink = myList.FirstLink()
	
	While (Link1 = Null Or  Link2 = Null)
		If TItem(currentLink._value).val = num1 Then Link1 = currentLink
		If TItem(currentLink._value).val = num2 Then Link2 = currentLink
		
		
		If currentLink = myList.LastLink() Then Exit
		
		currentLink = currentLink.NextLink()
		
	Wend

	SwapLinks(Link1, Link2)
	
End Function


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