public static int binarySearch( int array[], int value ) { if ( null == array ) return -1; int low = 0, high = array.length - 1, middle = -1; while ( low <= high ) { middle = ( low + high ) / 2; if ( value == array[ low ] ) { return low ; } if ( value == array[ high ] ) { return high; } if ( value == array[ middle ] ) { return middle; } else if ( value > array[ middle ] ) { low = middle + 1; } else { high = middle - 1; } } }
public static void bubblingSort( int array[] ) { if ( null == array ) return ; int temp; for ( int i = 0; i < array.length - 1; i++ ) { for ( int j = i ; i < array.length - i - 1; j++ ) { if ( array[ i ] > array[ j ] ) { temp = array[ j ]; array[ j ] = array[ i ]; array[ i ] = temp; } } } }
已有 0 人发表留言,猛击->>这里<<-参与讨论
ITeye推荐