**fig6_12.txt** /* 1*/ template /* 2*/ Element_Type /* 3*/ Binary_Heap:: /* 4*/ Delete_Min( ) /* 5*/ { /* 6*/ unsigned int Child; /* 7*/ Element_Type Min_Element, Last_Element; /* 8*/ if( Is_Empty( ) ) /* 9*/ { /*10*/ Error( "Priority queue is empty" ); /*11*/ return Elements[ 0 ]; // If error is not fatal. /*12*/ } /*13*/ Min_Element = Elements[ 1 ]; /*14*/ Last_Element = Elements[ Size-- ]; /*15*/ for( int i = 1; i * 2 <= Size; i = Child ) /*16*/ { /*17*/ // Find smaller child. /*18*/ Child = i * 2; /*19*/ if( Child != Size ) /*20*/ if( Elements[ Child + 1 ] < Elements[ Child ] ) /*21*/ Child++; /*22*/ // Percolate one level. /*23*/ if( Last_Element > Elements[ Child ] ) /*24*/ Elements[ i ] = Elements[ Child ]; /*25*/ else /*26*/ break; /*27*/ } /*28*/ Elements[ i ] = Last_Element; /*29*/ return Min_Element; /*30*/ }