1. template <class RandomAccessIterator> 
  2. inline void push_heap(RandomAccessIterator first, RandomAccessIterator last) { 
  3.     __push_heap_aux(first, last, distance_type(first), value_type(first)); 
  4.  
  5. template <class RandomAccessIterator, class Distance, class T> 
  6. inline void __push_heap_aux(RandomAccessIterator first, 
  7.                            RandomAccessIterator last, Distance*, T*) { 
  8.     __push_heap(first, Distance((last - first) - 1, Distance(0), T(*(last - 1))); 

 

 
    
  1. template <class RandomAccessIterator, class Distance, class T>                    
  2. void __push_heap(RandomAccessIterator first, Distance holeIndex,
  3.                  Distance topIndex, T value) {                                    
  4.     Distance parent = (holeIndex - 1)/2; 
  5.     while(holeIndex > topIndex && *(first + parent) < value) {                    
  6.         *(first + holeIndex) = *(first + parent);                                 
  7.         holeIndex = parent;                                                       
  8.         parent = (holeIndex - 1)/2;                                               
  9.     }                                                                             
  10.     *(first + holeIndex) = value;