Skip to content

Latest commit

 

History

History
43 lines (24 loc) · 1.89 KB

CppStdIs_heap.md

File metadata and controls

43 lines (24 loc) · 1.89 KB

 

 

 

 

 

 

std::is_heap is an STL algorithm to check if a container is ordered like a heap.

 

 


#include <algorithm> #include <cassert> #include <vector> int main() {   //Create a std::vector   std::vector<int> v = {0,1,2,3,4,5,6,7,8,9};   //Assume std::vector is not a heap yet   assert(!std::is_heap(v.begin(),v.end()));   //make the std::vector a heap   std::make_heap(v.begin(),v.end());   //Assume std::vector is a heap now   assert(std::is_heap(v.begin(),v.end()));   //Assume the std::vector elements are ordered like a heap   assert(v == std::vector<int>( {9,8,6,7,4,5,2,0,3,1} ) ); }