WWDC 2018 Session 406 : Divide-and-Conquer Binary Search
stackoverflow : sorting - How do I insert an element at the correct position into a sorted array in Swift?
func sortedInsertionValue(_ value: String) {
var slice: Array<String>.SubSequence = mySortedArray[...]
while !slice.isEmpty {
let middle = slice.index(slice.startIndex, offsetBy: slice.count / 2 )
if value < slice[middle] {
slice = slice[..<middle]
} else {
slice = slice[slice.index(after: middle)...]
}
}
mySortedArray.insert(value, at: slice.startIndex)
}
'프로그래밍 > iOS,macOS' 카테고리의 다른 글
[swift] SCNProgram 쉐이더 투명 적용 (0) | 2024.10.31 |
---|---|
[swift] SceneKit uv animation (0) | 2024.08.22 |
[swift] swiftui fileImpoter로 파일 선택하기 (0) | 2024.08.08 |
[concurrency] Task, TaskGroup, task timeout (0) | 2023.02.28 |
[concurrency] swift async/await (0) | 2022.05.13 |
[Combine] 콜백 기반 여러 처리 결과를 배열로 받기 (0) | 2022.03.20 |
[SwiftUI] 오디오 레벨 에니메이션, Shape (0) | 2022.01.06 |
dataTaskPublisher 재시도 및 출력 타입 변경 (0) | 2021.10.16 |
Framework SPM 배포 (0) | 2021.09.24 |
URLSession.DataTaskPublisher (0) | 2021.09.17 |