From 90e23a6790f1f0a0e3704314a08be02114bcdf11 Mon Sep 17 00:00:00 2001 From: Coskun Deniz Date: Sat, 21 Aug 2021 19:44:58 +0100 Subject: [PATCH] declare 'index' as variable --- Insertion Sort/InsertionSort.swift | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Insertion Sort/InsertionSort.swift b/Insertion Sort/InsertionSort.swift index e24ede905..5f0b6c2b4 100644 --- a/Insertion Sort/InsertionSort.swift +++ b/Insertion Sort/InsertionSort.swift @@ -28,14 +28,13 @@ func insertionSort(_ array: [T]) -> [T] { guard array.count > 1 else { return array } var sortedArray = array - for index in 1.. 0, temp < sortedArray[currentIndex - 1] { - sortedArray[currentIndex] = sortedArray[currentIndex - 1] - currentIndex -= 1 + for var index in 1.. 0, temp < sortedArray[index - 1] { + sortedArray[index] = sortedArray[index - 1] + index -= 1 } - sortedArray[currentIndex] = temp + sortedArray[index] = temp } return sortedArray }