Skip to content

Commit b99f882

Browse files
committed
added chapter 11
1 parent c14829b commit b99f882

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

chapter11/01-SearchingAlgorithms.js

+4
Original file line numberDiff line numberDiff 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
}

chapter11/02-UsingSearchingAlgorithms.js

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
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

1313
console.log('********** Sequential Sort #3 **********');
1414

@@ -24,4 +24,10 @@ console.log(array.findMaxValue());
2424

2525
console.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));

0 commit comments

Comments
 (0)