正在加载图片...
int UFSets: Find( intx)( while( m pParentx >=0)x=m pArent(x template <class Type> MinHeap<Type>:: MinHeap( int Maxsize )i HMaxS ize maxsize pHeap= new Type[HMaxSize]: template <class Type> MinHeap<Type>: MinHeap( Type Array[, int n)i pHeap =new Type [HMax Size]; for( int i=0; i <n; i++)pHeap[]=Array [] Currents ize =n-1: t iPos=( CurrentSize-1)/2; while(iPos >=0)4 FilterDown(IPos, Currentsize ) template <class Type> void MinHeap<Type>:: Filter Down( int start, int end)t int i=star,j=2 start +1; if(j<end & pHeap[+1]<= pHeap[)j++ if( Temp < pHeap(=pHeapD: i=j;j=2*j+1; pHeap[= Temp template <class Type> void MinHeap<Type>: FilterUp( int end)i Type Temp= pHeap[]: while(1>0)( if( pHeap[l <=Temp )break; i=j;j=(j-1)/2;第 8 章 图 103 int UFSets :: Find ( int x ) { while ( m_pParent[x] >= 0 ) x = m_pParent[x]; return x; } template <class Type> MinHeap<Type> :: MinHeap ( int Maxsize ) { HMaxSize = Maxsize; pHeap = new Type[HMaxSize]; CurrentSize = -1; } template <class Type> MinHeap<Type> :: MinHeap ( Type Array[], int n ) { HMaxSize = ( n < MaxHeapSize ) ? MaxHeapSize : n; pHeap = new Type[HMaxSize]; for ( int i = 0; i < n; i++ ) pHeap[i] = Array[i]; CurrentSize = n-1; int iPos = ( CurrentSize - 1 ) / 2; while ( iPos >= 0 ) { FilterDown ( iPos, CurrentSize ); iPos--; } } template <class Type> void MinHeap<Type> :: FilterDown ( int start, int end ) { int i = start, j = 2 * start + 1; Type Temp = pHeap[i]; while ( j <= end ) { if ( j < end && pHeap[j+1] <= pHeap[j] ) j++; if ( Temp <= pHeap[j] ) break; pHeap[i] = pHeap[j]; i = j; j = 2 * j + 1; } pHeap[i] = Temp; } template <class Type> void MinHeap<Type> :: FilterUp ( int end ) { int i = end, j = ( end - 1 ) / 2; Type Temp = pHeap[i]; while ( i > 0 ) { if ( pHeap[j] <= Temp ) break; pHeap[i] = pHeap[j]; i = j; j = ( j - 1 ) / 2; }
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有