We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 8e955cd + 69cb42e commit aec126cCopy full SHA for aec126c
Shell Sort/ShellSortExample.swift
@@ -0,0 +1,33 @@
1
+//
2
+// ShellSortExample.swift
3
4
5
+// Created by Cheer on 2017/2/26.
6
7
8
+
9
+import Foundation
10
11
+public func shellSort(_ list: inout [Int]) {
12
13
+ var sublistCount = list.count / 2
14
15
+ while sublistCount > 0 {
16
17
+ for index in 0..<list.count {
18
19
+ guard index + sublistCount < list.count else { break }
20
21
+ if list[index] > list[index + sublistCount] {
22
+ swap(&list[index], &list[index + sublistCount])
23
+ }
24
25
+ guard sublistCount == 1 && index > 0 else { continue }
26
27
+ if list[index - 1] > list[index] {
28
+ swap(&list[index - 1], &list[index])
29
30
31
+ sublistCount = sublistCount / 2
32
33
+}
0 commit comments