writing is very inefficient. This is a lot of details. It seems that every time you write it, you have to find it again. Just write it.
// Binaryheap. CPP -- 2011-08-28-23.06 // purpose: // define methods of Class "binaryheap ". # include "stdafx. H "# include" binaryheap. H "// Private methods: // ----------------------- void binaryheap: m_percolateup (INT index) {node temp = m_heap [Index]; size_t I = index; size_t parent = (I-1)/2; while (I! = 0) {If (temp. weight <m_heap [Parent]. weight) {m_heap [I] = m_heap [Parent]; I = parent; parent = (I-1)/2;} else {m_heap [I] = temp; break;} If (0 = I) {m_heap [0] = temp;} // ----------------------- void binaryheap: m_percolatedown (INT index) {node temp = m_heap [Index]; int I = index; int child = I * 2 + 1; while (Child <m_currentsize) {If (child! = M_currentsize-1 & m_heap [Child + 1]. weight <m_heap [child]. weight) ++ child; if (temp. weight> m_heap [child]. weight) {m_heap [I] = m_heap [child]; I = Child; child = I * 2 + 1;} else {m_heap [I] = temp; break ;}} if (Child> = m_currentsize) {m_heap [I] = temp;} // ------------------- // public methods: // --------------------- binaryheap: binaryheap (INT size) {If (size <= 0) {STD: cerr <"Wrong size. "< STD: Endl; return;} m_heap = new node [size]; If (null = m_heap) {STD: cerr <"out of space. "<STD: Endl; return;} m_size = size; m_currentsize = 0;} // --------------------- // ----------------------- binaryheap ::~ Binaryheap (void) {Delete [] m_heap;} // ------------------- // define bool binaryheap: isempty (void) {If (0 = m_currentsize) return true; elsereturn false ;} // response bool binaryheap: isfull (void) {If (m_currentsize = m_size) return true; elsereturn false;} // response // ------------------- bool binaryheap :: insert (INT startindex, int endindex, int weight) {If (isfull () {STD: cerr <"heap is full already. "<STD: Endl; return false;} If (startindex> = m_size | startindex <0 | endindex> = m_size | endindex <0) {STD :: cerr <"wrong start index or end index. "<STD: Endl; return false;} m_heap [m_currentsize]. startindex = startindex; m_heap [m_currentsize]. endindex = endindex; m_heap [m_currentsize]. weight = weight; m_percolateup (m_currentsize); ++ m_currentsize; return true;} // ----------------------- // --------------------- bool binaryheap: deletemin (node * const pnode) {If (isempty () {STD: cerr <"heap is empty already. "<STD: Endl; return false;} * pnode = m_heap [0]; m_heap [0] = m_heap [-- m_currentsize]; m_percolatedown (0); Return true ;} //---------------------