Created
February 20, 2019 06:38
-
-
Save konratnox/abf71137659763327cdbeaffd1d298d9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function BinarySearch(t,A) // t - искомый элемент, | |
{ // A - упорядоченный массив, в котором ищем. | |
var i = 0, j = A.length, k; | |
while (i < j) | |
{ k = Math.floor((i+j)/2); | |
if (t <= A[k]) j = k; | |
else i = k+1; | |
} | |
if (A[ i ] === t) return i; // На выходе индекс искомого элемента. | |
else return -1; // Если искомого элемента нет в массиве, то -1. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment