File tree Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Expand file tree Collapse file tree 2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -57,11 +57,15 @@ function ArrayList(){
5757 while ( low <= high ) {
5858 mid = Math . floor ( ( low + high ) / 2 ) ;
5959 element = array [ mid ] ;
60+ console . log ( 'mid element is ' + element ) ;
6061 if ( element < item ) {
6162 low = mid + 1 ;
63+ console . log ( 'low is ' + low ) ;
6264 } else if ( element > item ) {
6365 high = mid - 1 ;
66+ console . log ( 'high is ' + high ) ;
6467 } else {
68+ console . log ( 'found it' ) ;
6569 return mid ;
6670 }
6771 }
Original file line number Diff line number Diff line change 1- function createNonSortedArray ( ) {
1+ function createNonSortedArray ( items ) {
22 var array = new ArrayList ( ) ;
33
4- for ( var i = 5 ; i > 0 ; i -- ) {
4+ for ( var i = items ; i > 0 ; i -- ) {
55 array . insert ( i ) ;
66 }
77
88 return array ;
99}
1010
11- var array = createNonSortedArray ( ) ;
11+ var array = createNonSortedArray ( 5 ) ;
1212
1313console . log ( '********** Sequential Sort #3 **********' ) ;
1414
@@ -24,4 +24,10 @@ console.log(array.findMaxValue());
2424
2525console . log ( '********** Binary Search #3 **********' ) ;
2626
27- console . log ( array . binarySearch ( 3 ) ) ;
27+ console . log ( array . binarySearch ( 3 ) ) ;
28+
29+ console . log ( '********** Binary Search #2 **********' ) ;
30+
31+ var array = createNonSortedArray ( 8 ) ;
32+
33+ console . log ( array . binarySearch ( 2 ) ) ;
You can’t perform that action at this time.
0 commit comments