SwapElements()

Syntax

SwapElements(LinkedList(), *FirstElement, *SecondElement)
Description
Swaps 2 elements of the specified list. The '*FirstElement' and '*SecondElement' parameters must be pointers to valid list elements. This function is very useful if you want to sort or reorganize quickly a list. It should be used with care and only by advanced users.

Parameters:
LinkedList() - The name of your linked 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:
This function does not return anything.

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

Supported OS

All

<- SelectElement() - LinkedList Index