Skip to content

Commit 75d866a

Browse files
author
mattthousand
committed
Update README.
1 parent 411cbd2 commit 75d866a

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

Heap Sort/README.markdown

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ Here's how you can implement heap sort in Swift:
4848

4949
```swift
5050
extension Heap {
51-
public mutating func sort() -> [T] {
52-
for i in (elements.count - 1).stride(through: 1, by: -1) {
53-
swap(&elements[0], &elements[i])
54-
shiftDown(index: 0, heapSize: i)
55-
}
51+
public mutating func sort() -> [T] {
52+
for i in stride(from: (elements.count - 1), through: 1, by: -1) {
53+
swap(&elements[0], &elements[i])
54+
shiftDown(0, heapSize: i)
55+
}
5656
return elements
57-
}
57+
}
5858
}
5959
```
6060

@@ -70,10 +70,10 @@ Because we need a max-heap to sort from low-to-high, you need to give `Heap` the
7070
We can write a handy helper function for that:
7171

7272
```swift
73-
public func heapsort<T>(a: [T], _ sort: (T, T) -> Bool) -> [T] {
74-
let reverseOrder = { i1, i2 in sort(i2, i1) }
75-
var h = Heap(array: a, sort: reverseOrder)
76-
return h.sort()
73+
public func heapsort<T>(_ a: [T], _ sort: @escaping (T, T) -> Bool) -> [T] {
74+
let reverseOrder = { i1, i2 in sort(i2, i1) }
75+
var h = Heap(array: a, sort: reverseOrder)
76+
return h.sort()
7777
}
7878
```
7979

0 commit comments

Comments
 (0)