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