๐ฑ๐ iOS/๐ Apple Developer Documentation
[Swift / Array] swapAt(_:_:)
๋น๋น bibi
2022. 9. 28. 12:08
swapAt(::)
- ์ปฌ๋ ์ ์ ์ง์ ์ธ๋ฑ์ค์ ๊ฐ์ ๊ตํํฉ๋๋ค.
mutating func swapAt(
_ i: Self.Index,
_ j: Self.Index
)
ํ๋ผ๋ฏธํฐ
i
: ๊ตํํ 1 ๋ฒ์งธ ๊ฐ์ ์ธ๋ฑ์คj
: ๊ตํํ 2 ๋ฒ์งธ ๊ฐ์ ์ธ๋ฑ์ค
์ค๋ช
๋ ํ๋ผ๋ฏธํฐ๊ฐ ๋ชจ๋ endIndex
์ ๊ฐ์ง ์์, ์ปฌ๋ ์
์ ์ ํจํ ์ธ๋ฑ์ค๋ค์ด์ด์ผ ํฉ๋๋ค. i
์ j
์ ๊ฐ์ ์ธ๋ฑ์ค๋ฅผ ์ฌ์ฉํด **swapAt(_:_:)
๋ฅผ ํธ์ถํ๋ ๊ฒ์ ์๋ฌด ํจ๊ณผ๊ฐ ์์ต๋๋ค.
๋ณต์ก๋
O(1)