inline void __pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _RandomAccessIterator __result, _Tp __value, _Distance*) { *__result = *__first;//把原始堆的根节点元素放在容器的末尾 //调整剩下的节点元素,使其成为新的heap __adjust_heap(__first, _Distance(0), _Distance(__last - __first), __value); }
inline void __pop_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _RandomAccessIterator __result, _Tp __value, _Compare __comp, _Distance*) { *__result = *__first; __adjust_heap(__first, _Distance(0), _Distance(__last - __first), __value, __comp); }
void make_heap(_Iterator __first, _Iterator __last) { if (__last - __first < 2) return; const _Distance __len = __last - __first; _Distance __parent = (__len - 2) / 2; while (true) { _Value __value = *(__first + __parent); __adjust_heap(__first, __parent, __len, __value); if (__parent == 0) return; __parent--; } }
void __make_heap(_RandomAccessIterator __first, _RandomAccessIterator __last, _Tp*, _Distance*) { if (__last - __first < 2) return; _Distance __len = __last - __first; _Distance __parent = (__len - 2)/2; while (true) { __adjust_heap(__first, __parent, __len, _Tp(*(__first + __parent))); if (__parent == 0) return; __parent--; } }
void __pop_heap(_Iterator __first, _Iterator __last, _Iterator __result) { _Value __value = *__result; *__result = *__first; __adjust_heap(__first, _Distance(0), _Distance(__last - __first), __value); }