Sorting algorithms/Heapsort: Difference between revisions

Updated second D entry, and swapped the two entries
m (moved PL/I)
(Updated second D entry, and swapped the two entries)
Line 608:
 
=={{header|D}}==
<lang d>import std.stdio, std.container;
 
void heapSort(T)(T[] data) /*pure nothrow*/ {
for (auto h = data.heapify; !h.empty; h.removeFront) {}
 
void main() {
auto arritems = [7, 6, 5, 9, 8, 4, 3, 1, 2, 0];
items.heapSort;
items.writeln(arr);
}</lang>
 
A lower level implementation:
<lang d>import std.stdio, std.algorithm;
 
Line 633 ⟶ 646:
siftDown(seq, 0, end - 1);
}
 
void main() {
auto arr = [7, 6, 5, 9, 8, 4, 3, 1, 2, 0];
inplaceHeapSort(arr);
writeln(arr);
}</lang>
===Using Standard Functions===
<lang d>import std.stdio, std.container;
 
void inplaceHeapSort(T)(T[] data) {
auto h = heapify(data);
while (!h.empty)
h.removeFront();
}