ranges::is_heap

ranges::is_heap (힙 성질 검사 — ranges)

범위가 최대 힙인지 검사하는 ranges 버전 알고리즘이에요. <algorithm> 헤더에 있어요.

출처: cppreference

본문

std::ranges::is_heap은 범위가 최대 힙인지 검사해요.

namespace std::ranges {
template< class R, class Proj = std::identity,
          std::indirect_strict_weak_order<std::projected<ranges::iterator_t<R>, Proj>>
              Comp = ranges::less >
constexpr bool is_heap( R&& r, Comp comp = {}, Proj proj = {} );
}
  • 힙이란 부모가 자식보다 크거나 같도록 표현된 완전 이진 트리 구조예요.
  • 반환 값: 범위가 최대 힙이면 true.
  • 복잡도: 선형.
std::vector<int> v{9, 5, 6, 1, 3};
std::ranges::make_heap(v);
bool ok = std::ranges::is_heap(v);   // true

힙 연산(ranges::make_heap 등) 후 상태가 올바른지 검증할 때 쓰는 ranges 버전이에요.

더 알아보기 (Learn more)

cppreference