File tree Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Expand file tree Collapse file tree 1 file changed +9
-9
lines changed Original file line number Diff line number Diff line change 8
8
9
9
import Foundation
10
10
11
- public func shellSort( _ list : inout [ Int ] )
12
- {
13
- var sublistCount = list. count / 2
11
+ public func shellSort( _ list: inout [ Int ] ) {
14
12
15
- while sublistCount > 0
16
- {
17
- for index in 0 ..< list. count{
18
-
13
+ var sublistCount = list. count / 2
14
+
15
+ while sublistCount > 0 {
16
+
17
+ for index in 0 ..< list. count {
18
+
19
19
guard index + sublistCount < list. count else { break }
20
20
21
- if list [ index] > list [ index + sublistCount] {
21
+ if list [ index] > list [ index + sublistCount] {
22
22
swap ( & list[ index] , & list[ index + sublistCount] )
23
23
}
24
24
25
25
guard sublistCount == 1 && index > 0 else { continue }
26
26
27
- if list [ index - 1 ] > list [ index] {
27
+ if list [ index - 1 ] > list [ index] {
28
28
swap ( & list[ index - 1 ] , & list[ index] )
29
29
}
30
30
}
You can’t perform that action at this time.
0 commit comments