10000
We read every piece of feedback, and take your input very seriously.
10000 To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ae77f56 commit 71bfd71Copy full SHA for 71bfd71
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..<arr.count{
18
19
+ guard index + sublistCount < arr.count else { break }
20
21
+ if arr[index] > arr[index + sublistCount]{
22
+ swap(&arr[index], &arr[index + sublistCount])
23
+ }
24
25
+ guard sublistCount == 1 && index > 0 else { continue }
26
27
+ if arr[index - 1] > arr[index]{
28
+ swap(&arr[index - 1], &arr[index])
29
30
31
+ sublistCount = sublistCount / 2
32
33
+}
0 commit comments