Skip to content

Commit 1bc6990

Browse files
authored
Create ShellSortExample.swift
Inner while loop was slightly incorrect - for example try array [64, 20, 50, 33, 72, 10, 23, -1, 4,-2,-3] with previous version.
1 parent 17bf20d commit 1bc6990

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Diff for: Shell Sort/ShellSortExample.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public func shellSort(_ list : inout [Int]) {
2222

2323
guard sublistCount == 1 && index > 0 else { continue }
2424

25-
while list[index - 1] > list[index] && index - 1 > 0 {
25+
while index > 0 && list[index - 1] > list[index] {
2626
swap(&list[index - 1], &list[index])
2727
index -= 1
2828
}

0 commit comments

Comments
 (0)