Files
cppdraft_translate/cppdraft/alg/heap/operations/general.md
2025-10-25 03:02:53 +03:00

1.4 KiB
Raw Blame History

[alg.heap.operations.general]

26 Algorithms library [algorithms]

26.8.8 Heap operations [alg.heap.operations]

26.8.8.1 General [alg.heap.operations.general]

1

#

A random access range [a, b) is aheap with respect to comp and proj for a comparator and projection comp and proj if its elements are organized such that:

  • (1.1)

    With N = b - a, for all i, 0<i<N, bool(invoke(comp, invoke(proj, a[⌊ˆ’12⌋]), invoke(proj, a[i]))) is false.

  • (1.2)

    *a may be removed by pop_heap, or a new element added by push_heap, in O(logN) time.

2

#

These properties make heaps useful as priority queues.

3

#

make_heap converts a range into a heap andsort_heap turns a heap into a sorted sequence.