Skip to content

Commit 7dd9de0

Browse files
authored
Update ShellSortExample.swift
fix code. And apologize for my carelessness.
1 parent ae1da6f commit 7dd9de0

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

Shell Sort/ShellSortExample.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ public func shellSort(_ list : inout [Int])
1414

1515
while sublistCount > 0
1616
{
17-
for var index in 0..<arr.count{
17+
for var index in 0..<list.count{
1818

19-
guard index + sublistCount < arr.count else { break }
19+
guard index + sublistCount < list.count else { break }
2020

21-
if arr[index] > arr[index + sublistCount]{
22-
swap(&arr[index], &arr[index + sublistCount])
21+
if list[index] > list[index + sublistCount]{
22+
swap(&list[index], &list[index + sublistCount])
2323
}
2424

2525
guard sublistCount == 1 && index > 0 else { continue }
26-
27-
while arr[index - 1] > arr[index] && index - 1 > 0 {
28-
swap(&arr[index - 1], &arr[index])
26+
27+
while list[index - 1] > list[index] && index - 1 > 0 {
28+
swap(&list[index - 1], &list[index])
2929
index -= 1
3030
}
3131
}

0 commit comments

Comments
 (0)