We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 28f1fc3 + aef1bb7 commit cd7b83dCopy full SHA for cd7b83d
Insertion Sort/README.markdown
@@ -91,16 +91,18 @@ Here is an implementation of insertion sort in Swift:
91
92
```swift
93
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
+ var a = array // 1
+ for x in 1..<a.count { // 2
+ var y = x
+ while y > 0 && a[y] < a[y - 1] { // 3
+ a.swapAt(y - 1, y)
+ y -= 1
100
+ }
101
}
- }
102
- return a
+ return a
103
104
+
105
106
```
107
108
Put this code in a playground and test it like so:
0 commit comments