File tree 1 file changed +9
-9
lines changed
1 file changed +9
-9
lines changed Original file line number Diff line number Diff line change @@ -48,13 +48,13 @@ Here's how you can implement heap sort in Swift:
48
48
49
49
``` swift
50
50
extension Heap {
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
- }
56
- return elements
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)
57
55
}
56
+ return elements
57
+ }
58
58
}
59
59
```
60
60
@@ -71,9 +71,9 @@ We can write a handy helper function for that:
71
71
72
72
``` swift
73
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 ()
74
+ let reverseOrder = { i1, i2 in sort (i2, i1) }
75
+ var h = Heap (array : a, sort : reverseOrder)
76
+ return h.sort ()
77
77
}
78
78
```
79
79
You can’t perform that action at this time.
0 commit comments