Skip to content

Commit cd7b83d

Browse files
authored
Merge pull request kodecocodes#617 from mrabins/patch-2
Swap changes
2 parents 28f1fc3 + aef1bb7 commit cd7b83d

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

Insertion Sort/README.markdown

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,18 @@ Here is an implementation of insertion sort in Swift:
9191

9292
```swift
9393
func insertionSort(_ array: [Int]) -> [Int] {
94-
var a = array // 1
95-
for x in 1..<a.count { // 2
96-
var y = x
97-
while y > 0 && a[y] < a[y - 1] { // 3
98-
swap(&a[y - 1], &a[y])
99-
y -= 1
94+
var a = array // 1
95+
for x in 1..<a.count { // 2
96+
var y = x
97+
while y > 0 && a[y] < a[y - 1] { // 3
98+
a.swapAt(y - 1, y)
99+
y -= 1
100+
}
100101
}
101-
}
102-
return a
102+
return a
103103
}
104+
105+
104106
```
105107

106108
Put this code in a playground and test it like so:

0 commit comments

Comments
 (0)