arr=[10,11,14,18,21,25,30,36,40,41,46,50,65,68,90,99];
function draw() {
canvas=document.getElementById('canvas');
ctx = this.canvas.getContext("2d");
for (var i = 0; i < arr.length; i++) {
drawNode(33+(62*i),40,25,arr[i],ctx);
}
}
function searchIt() {
var val=document.getElementById('search-field').value;
var res=binarySearch(val),
indices=res.traverses,
count=0,status;
var intId=setInterval(()=>{
index=indices.shift();
if (index > -1) {
if( index == res.found)
foundNode(33+(62*index),40,25,arr[index],ctx);
else
highlightNode(33+(62*index),40,25,arr[index],ctx);
var checks=document.getElementById("checkCount");
checks.innerHTML=""+(++count);
}
else{
status="Found "+val+" at index = "+res.found+" in "+count+" checks.";
if(res.found==-1){
status=val+" not found in the array.";
}
clearInterval(intId);
document.getElementById("result").innerHTML=status;
}
},2000);
}