Swapped function
Namespace: Microsoft.Quantum.Arrays
Package: Microsoft.Quantum.Standard
Applies a swap of two elements in an array.
function Swapped<'T> (firstIndex : Int, secondIndex : Int, arr : 'T[]) : 'T[]
Input
firstIndex : Int
Index of the first element to be swapped.
secondIndex : Int
Index of the second element to be swapped.
arr : 'T[]
Array with elements to be swapped.
Output : 'T[]
The array with the in place swap applied.
Type Parameters
'T
Example
// The following returns [0, 3, 2, 1, 4]
Swapped(1, 3, [0, 1, 2, 3, 4]);
Feedback
Submit and view feedback for