java - 二项队列的查找最小索引
大家讲道理
大家讲道理 2017-04-18 10:01:19
0
1
273

源代码
代码中的findMinIndex()方法如下:

private int findMinIndex( )
{
    int i;
    int minIndex;

    for( i = 0; theTrees[ i ] == null; i++ )
        ;

    for( minIndex = i; i < theTrees.length; i++ )
        if( theTrees[ i ] != null &&
            theTrees[ i ].element.compareTo( theTrees[ minIndex ].element ) < 0 )
            minIndex = i;

    return minIndex;
}

当中的第一个循环作用跟目的是什么?如果数组如[1,null,3,4]那么找出来的最小值不是错的?

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(1)
小葫芦

Find the first element subscript in the array that is not null. The purpose is to ensure that in the second step, the array element indicated by minIndex is not null.
[1,null,3,4] can find the minimum value because null has been checked in the second loop

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!