From 1bc6990fe584080dcca0249bdb05d8a7c56907cd Mon Sep 17 00:00:00 2001 From: Darragh Date: Sat, 10 Jun 2017 15:49:46 +0100 Subject: [PATCH] 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. --- Shell Sort/ShellSortExample.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Shell Sort/ShellSortExample.swift b/Shell Sort/ShellSortExample.swift index e9cee7543..df0842770 100644 --- a/Shell Sort/ShellSortExample.swift +++ b/Shell Sort/ShellSortExample.swift @@ -22,7 +22,7 @@ public func shellSort(_ list : inout [Int]) { guard sublistCount == 1 && index > 0 else { continue } - while list[index - 1] > list[index] && index - 1 > 0 { + while index > 0 && list[index - 1] > list[index] { swap(&list[index - 1], &list[index]) index -= 1 }