锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲综合三区,久久超级碰碰,中文字幕日韩一区二区不卡http://www.aygfsteel.com/saintqdd/zh-cnThu, 19 Jun 2025 20:38:28 GMTThu, 19 Jun 2025 20:38:28 GMT60JAVA瀹炵幇鐨凥eaphttp://www.aygfsteel.com/saintqdd/archive/2008/09/02/226404.html姘寸墰鈾俆oto姘寸墰鈾俆otoTue, 02 Sep 2008 07:51:00 GMThttp://www.aygfsteel.com/saintqdd/archive/2008/09/02/226404.htmlhttp://www.aygfsteel.com/saintqdd/comments/226404.htmlhttp://www.aygfsteel.com/saintqdd/archive/2008/09/02/226404.html#Feedback0http://www.aygfsteel.com/saintqdd/comments/commentRss/226404.htmlhttp://www.aygfsteel.com/saintqdd/services/trackbacks/226404.html@SuppressWarnings("unused")
public class MyHeap{
    
    
private static final int MAX_SIZE = 1001;

    
private int CUR_SIZE;      
   
    
private Comparable[] DATA;
    
    
public MyHeap() {
        CUR_SIZE 
= 0;
        DATA 
= new Comparable[ MAX_SIZE + 1 ];
    }

    
    
public MyHeap( Comparable [] items ) {
        CUR_SIZE 
= items.length;
        DATA 
= new Comparable[ items.length + 1 ];
        
        
forint i = 0; i < items.length; i++ )
            DATA[ i 
+ 1 ] = items[ i ];
        buildHeap();
    }

    
    
public void insert( Comparable x ) {
        
if( CUR_SIZE + 1 == DATA.length )
            doubleArray( );
        
        
// Percolate up
        int hole = ++CUR_SIZE;
        DATA[ 
0 ] = x;
        
        
for( ; x.compareTo( DATA[ hole / 2 ] ) < 0; hole /= 2 ) {
            DATA[ hole ] 
= DATA[ hole / 2 ];
        }

        DATA[ hole ] 
= x;
    }

    
    
public Comparable findMin( ) {
        
return DATA[ 1 ];
    }

    
    
public Comparable deleteMin( ) {
        Comparable minItem 
= findMin( );
        DATA[ 
1 ] = DATA[ CUR_SIZE-- ];
        percolateDown( 
1 );
        
        
return minItem;
    }

    
    
private void buildHeap( ) {
        
forint i = CUR_SIZE / 2; i > 0; i-- )
            percolateDown( i );
    }

    
    
public boolean isEmpty( ) {
        
return CUR_SIZE == 0;
    }

    
    
public int size( ) {
        
return CUR_SIZE;
    }

    
    
public void makeEmpty( ) {
        CUR_SIZE 
= 0;
    }

    
    
private void percolateDown( int hole ) {
        
int child;
        Comparable tmp 
= DATA[ hole ];
        
        
for( ; hole * 2 <= CUR_SIZE; hole = child ) {
            child 
= hole * 2;
            
if( child != CUR_SIZE &&
                    DATA[ child 
+ 1 ].compareTo( DATA[ child ] ) < 0 )
                child
++;
            
if( DATA[ child ].compareTo( tmp ) < 0 )
                DATA[ hole ] 
= DATA[ child ];
            
else
                
break;
        }

        DATA[ hole ] 
= tmp;
    }
    
    
    
private void doubleArray( ) {
        Comparable [] newArray;
        
        newArray 
= new Comparable[ DATA.length * 2 ];
        
forint i = 0; i < DATA.length; i++ )
            newArray[ i ] 
= DATA[ i ];
        DATA 
= newArray;
    }

}


]]>
主站蜘蛛池模板: 淮南市| 永川市| 富宁县| 昌乐县| 南雄市| 鲁山县| 盘锦市| 九龙县| 永嘉县| 新野县| 皮山县| 银川市| 吉林省| 霍邱县| 新泰市| 安龙县| 巴马| 精河县| 繁峙县| 红安县| 苍梧县| 资阳市| 新余市| 大洼县| 加查县| 桂阳县| 惠安县| 扎鲁特旗| 乐亭县| 梅州市| 鄂伦春自治旗| 沂水县| 仁布县| 通州市| 县级市| 尚志市| 烟台市| 乌恰县| 赤峰市| 武邑县| 宁安市|