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

38 lines
1.4 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[alg.heap.operations.general]
# 26 Algorithms library [[algorithms]](./#algorithms)
## 26.8 Sorting and related operations [[alg.sorting]](alg.sorting#alg.heap.operations.general)
### 26.8.8 Heap operations [[alg.heap.operations]](alg.heap.operations#general)
#### 26.8.8.1 General [alg.heap.operations.general]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10877)
A random access range [a, b) is a[*heap with respect to comp and proj*](#def:heap_with_respect_to_comp_and_proj "26.8.8.1General[alg.heap.operations.general]") for a comparator and projection comp and proj if its elements are organized such that:
- [(1.1)](#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.1.sentence-1)
- [(1.2)](#1.2)
*a may be removed by pop_heap, or
a new element added by push_heap,
in O(logN) time[.](#1.2.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10894)
These properties make heaps useful as priority queues[.](#2.sentence-1)
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/algorithms.tex#L10897)
make_heap converts a range into a heap andsort_heap turns a heap into a sorted sequence[.](#3.sentence-1)