Swapped function

Warning

This documentation refers to the Classic QDK, which has been replaced by the Modern QDK.

Please see https://aka.ms/qdk.api for the API documentation for the Modern QDK.

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]);