File tree 2 files changed +14
-4
lines changed
2 files changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -57,11 +57,15 @@ function ArrayList(){
57
57
while ( low <= high ) {
58
58
mid = Math . floor ( ( low + high ) / 2 ) ;
59
59
element = array [ mid ] ;
60
+ console . log ( 'mid element is ' + element ) ;
60
61
if ( element < item ) {
61
62
low = mid + 1 ;
63
+ console . log ( 'low is ' + low ) ;
62
64
} else if ( element > item ) {
63
65
high = mid - 1 ;
66
+ console . log ( 'high is ' + high ) ;
64
67
} else {
68
+ console . log ( 'found it' ) ;
65
69
return mid ;
66
70
}
67
71
}
Original file line number Diff line number Diff line change 1
- function createNonSortedArray ( ) {
1
+ function createNonSortedArray ( items ) {
2
2
var array = new ArrayList ( ) ;
3
3
4
- for ( var i = 5 ; i > 0 ; i -- ) {
4
+ for ( var i = items ; i > 0 ; i -- ) {
5
5
array . insert ( i ) ;
6
6
}
7
7
8
8
return array ;
9
9
}
10
10
11
- var array = createNonSortedArray ( ) ;
11
+ var array = createNonSortedArray ( 5 ) ;
12
12
13
13
console . log ( '********** Sequential Sort #3 **********' ) ;
14
14
@@ -24,4 +24,10 @@ console.log(array.findMaxValue());
24
24
25
25
console . log ( '********** Binary Search #3 **********' ) ;
26
26
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