在线文档教程
C++
算法 | Algorithm

std::is_heap_until

STD::是[医]堆[医]直到

Defined in header
template< class RandomIt > RandomIt is_heap_until( RandomIt first, RandomIt last (1)(since C++11)
template< class ExecutionPolicy, class RandomIt > RandomIt is_heap_until( ExecutionPolicy&& policy, RandomIt first, RandomIt last (2)(since C++17)
template< class RandomIt, class Compare > RandomIt is_heap_until( RandomIt first, RandomIt last, Compare comp (3)(since C++11)
template< class ExecutionPolicy, class RandomIt, class Compare > RandomIt is_heap_until( ExecutionPolicy&& policy, RandomIt first, RandomIt last, Compare comp (4)(since C++17)

检查范围[first, last)并发现最大的范围开始于first这是最大堆...

1%29个元素的比较operator<...

使用给定的二进制比较函数对3%29个元素进行比较。comp...

2,4%29与%281,3%29相同,但根据policy这些过载不参与过载解决,除非std::is_execution_policy_v<std::decay_t<ExecutionPolicy>>是真的

参数

first, last-the range of elements to examine
policy-the execution policy to use. See execution policy for details.
comp-comparison function object (i.e. an object that satisfies the requirements of Compare) which returns ​true if the first argument is less than the second. The signature of the comparison function should be equivalent to the following: bool cmp(const Type1 &a, const Type2 &b The signature does not need to have const &, but the function object must not modify the objects passed to it. The types Type1 and Type2 must be such that an object of type RandomIt can be dereferenced and then implicitly converted to both of them. ​

类型要求

---它必须符合RandomAccessIterator的要求。

返回值

最大范围的上限,起始于first这是最大堆,也就是最后一个迭代器it哪个范围[first, it)最大堆...

复杂性

直线在之间的距离firstlast...

例外

带有名为ExecutionPolicy报告错误如下:

  • 如果执行作为算法一部分调用的函数,则引发异常ExecutionPolicy是其中之一标准政策,,,std::terminate叫做。对于任何其他人ExecutionPolicy,行为是由实现定义的。

  • 如果算法不能分配内存,std::bad_alloc被扔了。

注记

最大堆是一系列元素[f,l)具有以下属性:

  • 带着N = l - f,为所有人0 < i < N,,,f[floor(i-12)]比不上f[i]...

  • 可以使用std::push_heap()

  • 第一个元素可以使用std::pop_heap()

二次

#include <iostream> #include <algorithm> #include <vector> int main() { std::vector<int> v { 3, 1, 4, 1, 5, 9 }; std::make_heap(v.begin(), v.end() // probably mess up the heap v.push_back(2 v.push_back(6 auto heap_end = std::is_heap_until(v.begin(), v.end() std::cout << "all of v: "; for (auto i : v) std::cout << i << ' '; std::cout << '\n'; std::cout << "only heap: "; for (auto i = v.begin( i != heap_end; ++i) std::cout << *i << ' '; std::cout << '\n'; }

二次

产出:

二次

all of v: 9 5 4 1 1 3 2 6 only heap: 9 5 4 1 1 3 2

二次

另见

is_heap (C++11)checks if the given range is a max heap (function template)

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/Algorithm/is[医]堆[医]直到