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

reverse()

Reverses the elements of the collection in place. コレクションの要素をその場で逆順にします。

Declaration 宣言

mutating func reverse()
Available when Base conforms to MutableCollection. BaseMutableCollectionに準拠する時に利用可能です。

Discussion 解説

The following example reverses the elements of an array of characters: 以下の例は、文字列からなる配列の要素を逆順にします:


var characters: [Character] = ["C", "a", "f", "é"]
characters.reverse()
print(characters)
// Prints "["é", "f", "a", "C"]

Complexity: O(n), where n is the number of elements in the collection. 計算量:O(n)、ここでnはコレクションの中の要素数です。