Instance Method インスタンスメソッド

swapAt(_:_:)

Exchanges the values at the specified indices of the collection. そのコレクションの指定インデックスでの値を交換します。

Declaration 宣言

mutating func swapAt(_ i: Int, _ j: Int)

Parameters パラメータ

i

The index of the first value to swap. 交換する1つ目の値のインデックス。

j

The index of the second value to swap. 交換する2つ目の値のインデックス。

Discussion 解説

Both parameters must be valid indices of the collection that are not equal to endIndex. Calling swapAt(_:_:) with the same index as both i and j has no effect. 両方のパラメータは、このコレクションの有効なインデックスで、endIndexと等しくない必要があります。swapAt(_:_:)ij両方で同じインデックスで呼び出すことは、効果を持ちません。

Complexity: O(1) 計算量:O(1)

See Also 参照

Reordering an Array's Elements 配列の要素を再配列します