home | login | register | DMCA | contacts | help | donate |

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
А Б В Г Д Е Ж З И Й К Л М Н О П Р С Т У Ф Х Ц Ч Ш Щ Э Ю Я

 fantasy space fantasy fantasy is horrors heroic prose   military   child   russian detective   action   child   ironical   historical   political western adventure adventure (child) child's stories love religion antique Scientific literature biography business home pets animals art history computers linguistics mathematics religion home_garden sport technique publicism philosophy chemistry close

Example

`int main() {`

` int A[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };`

` make_heap(A, A + 9);`

` cout << "[A, A + 9) = ";`

` copy (A, A + 9, ostream_iterator(cout, " "));`

` push_heap(A, A + 10);`

` cout << endl << "[A, A + 10) = ";`

` copy (A, A + 10, ostream_iterator(cout, " "));`

` cout << endl;`

`}`

The output is

`[A, A + 9) = 8 7 6 3 4 5 2 1 0`

`[A, A + 10) = 9 8 6 3 7 5 2 1 0 4`

Notes

[1] A heap is a particular way of ordering the elements in a range of random access iterators [f, l). The reason heaps are useful (especially for sorting, or as priority queues) is that they satisfy two important properties. First, *f is the largest element in the heap. Second, it is possible to add an element to a heap (using push_heap), or to remove *f, in logarithmic time. Internally, a heap is a tree represented as a sequential range. The tree is constructed so that that each node is less than or equal to its parent node.

Preconditions | Standard Template Library Programmer`s Guide | pop_heap