Algosim documentation: VarSwap

VarSwap

Swaps two elements in a linear container variable.

Syntax

If X is an lvalue and a container and i and j are valid indices in X, then VarSwap(X, i, j) swaps the elements with indices i and j and returns success.

This is the procedural version of swap.

Examples

v ≔ SequenceVector(10)
(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
VarSwap(v, 1, −1)
success
v
(10, 2, 3, 4, 5, 6, 7, 8, 9, 1)

See also