Anonymous user
Sorting algorithms/Heapsort: Difference between revisions
Updated second D entry
m (→version 1: added some verbage in the REXX section header (version 1). -- ~~~~) |
(Updated second D entry) |
||
Line 623:
<lang d>import std.stdio, std.algorithm;
void
static void siftDown(R seq, in size_t start,
in size_t end) pure nothrow @safe @nogc {
for (size_t root = start; root * 2 + 1 <= end; ) {
auto child = root * 2 + 1;
Line 639:
if (seq.length > 1)
foreach_reverse (immutable start; 1 .. (seq.length - 2) / 2 + 2)
siftDown(seq, start - 1, seq.length - 1);
foreach_reverse (immutable end; 1 .. seq.length) {
swap(seq[end], seq[0]);
siftDown(seq, 0, end - 1);
Line 649:
void main() {
auto
data.heapSort;
data.writeln
}</lang>
|