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.
1 parent 08abb81 commit 0d5d8d3Copy full SHA for 0d5d8d3
Insertion Sort/README.markdown
@@ -91,7 +91,7 @@ Here is an implementation of insertion sort in Swift:
91
92
```swift
93
func insertionSort(_ array: [Int]) -> [Int] {
94
- var a = array // 1
+ var a = array
95
for x in 1..<a.count { // 2
96
var y = x
97
while y > 0 && a[y] < a[y - 1] { // 3
@@ -101,6 +101,20 @@ func insertionSort(_ array: [Int]) -> [Int] {
101
}
102
return a
103
104
+
105
+func insertionSort(_ array: [Int]) -> [Int] {
106
+ var a = array // 1
107
+ for x in 1..<a.count { // 2
108
+ var y = x
109
+ while y > 0 && a[y] < a[y - 1] { // 3
110
+ a.swapAt(y - 1, y)
111
+ y -= 1
112
+ }
113
114
+ return a
115
+}
116
117
118
```
119
120
Put this code in a playground and test it like so:
0 commit comments