//顺序查找文本数据 function seqSearch(arr,data) { for(var i=0;i<arr.length;i++) { if(arr[i]==data) { return i; } } return -1; } //二分查找 function binSearch(arr,data) { var upperBound = arr.length - 1; var lowerBound = 0; while (lowerBound <=upperBound) { var mid = Math.floor((upperBound + lowerBound) / 2); if (arr[mid] < data) { lowerBound = mid + 1; } else if (arr[mid] > data) { upperBound = mid - 1; } else { return mid; } } return -1; } function insertionsort(arr) { var temp, inner; for (var outer = 1; outer <= arr.length-1; outer++) { temp = arr[outer]; inner = outer; while (inner>0&&(arr[inner-1]>=temp)) { arr[inner] = arr[inner - 1]; --inner; } arr[inner] = temp; } }