Skip to content

Commit

Permalink
Merge pull request #1931 from Poita/bug7287
Browse files Browse the repository at this point in the history
Fix Issue 7287 - BinaryHeap example
  • Loading branch information
monarchdodra committed Feb 13, 2014
2 parents 4a7f1a9 + 80ef8ef commit a60b269
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions std/container.d
Expand Up @@ -3742,17 +3742,6 @@ If $(D Store) is a range, the $(D BinaryHeap) cannot grow beyond the
size of that range. If $(D Store) is a container that supports $(D
insertBack), the $(D BinaryHeap) may grow by adding elements to the
container.
Example:
----
// Example from "Introduction to Algorithms" Cormen et al, p 146
int[] a = [ 4, 1, 3, 2, 16, 9, 10, 14, 8, 7 ];
auto h = heapify(a);
// largest element
assert(h.front == 16);
// a has the heap property
assert(equal(a, [ 16, 14, 10, 9, 8, 7, 4, 3, 2, 1 ]));
----
*/
struct BinaryHeap(Store, alias less = "a < b")
if (isRandomAccessRange!(Store) || isRandomAccessRange!(typeof(Store.init[])))
Expand Down Expand Up @@ -4089,6 +4078,18 @@ must be collected.
}
}

///
unittest
{
// Example from "Introduction to Algorithms" Cormen et al, p 146
int[] a = [ 4, 1, 3, 2, 16, 9, 10, 14, 8, 7 ];
auto h = heapify(a);
// largest element
assert(h.front == 16);
// a has the heap property
assert(equal(a, [ 16, 14, 10, 8, 7, 9, 3, 2, 4, 1 ]));
}

/**
Convenience function that returns a $(D BinaryHeap!Store) object
initialized with $(D s) and $(D initialSize).
Expand Down

0 comments on commit a60b269

Please sign in to comment.