Skip to content

Commit 40a8102

Browse files
author
Lee
committed
Update words to match the code.
1 parent e592ed6 commit 40a8102

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

Insertion Sort/README.markdown

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ func insertionSort(_ array: [Int]) -> [Int] {
168168
}
169169
```
170170

171-
The line at `//1` is what shifts up the previous elements by one position. At the end of the inner loop, `y` is the destination index for the new number in the sorted portion, and the line at `//2` copies this number into place.
171+
The line at `//1` is what shifts up the previous elements by one position. At the end of the inner loop, `currentIndex` is the destination index for the new number in the sorted portion, and the line at `//2` copies this number into place.
172172

173173
## Making it generic
174174

@@ -187,10 +187,10 @@ The new parameter `isOrderedBefore: (T, T) -> Bool` is a function that takes two
187187
The only other change is in the inner loop, which now becomes:
188188

189189
```swift
190-
while y > 0 && isOrderedBefore(temp, a[y - 1]) {
190+
while currentIndex > 0 && isOrderedBefore(temp, sortedArray[currentIndex - 1]) {
191191
```
192192

193-
Instead of writing `temp < a[y - 1]`, we call the `isOrderedBefore()` function. It does the exact same thing, except we can now compare any kind of object, not just numbers.
193+
Instead of writing `temp < sortedArray[currentIndex - 1]`, we call the `isOrderedBefore()` function. It does the exact same thing, except we can now compare any kind of object, not just numbers.
194194

195195
To test this in a playground, do:
196196

0 commit comments

Comments
 (0)