SwapElements()

Syntax

SwapElements(List(), *FirstElement, *SecondElement)
Description
Swaps the position of two elements in the specified list. This command is a fast way to reorganize a list, because it does not actually move the element data itself.

Parameters

List() The name of your list variable, created with the NewList function. You must include the brackets after the list name.
*FirstElement Address of the first element to swap. You can get this address by using the @ operator on the list name.
*SecondElement Address of the second element to swap. You can get this address by using the @ operator on the list name.

Return value

None.

Example

  NewList Numbers()
  
  For k=0 To 10
    AddElement(Numbers())
    Numbers() = k
  Next
    
  SelectElement(Numbers(), 3) ; Get the 4th element (first element is 0)
  *FirstElement = @Numbers()
  
  SelectElement(Numbers(), 9) ; Get the 10th element
  *SecondElement = @Numbers()
  
  ; Swap the 3 with the 9
  ;
  SwapElements(Numbers(), *FirstElement, *SecondElement)
    
  ; Prove it
  ;
  ForEach Numbers()
    Debug Numbers()
  Next

See Also

MoveElement()

Supported OS

All

<- SplitList() - List Index