Files
GrokAlgorithms/Chapter4_QuickSort/Task4_4_BinSearch.cs
2025-07-26 17:46:42 +03:00

16 lines
515 B
C#

static class Task4_4
{
public static int BinSearch(IEnumerable<int> collection, int target, int left, int right)
{
if (left > right)
return left; // позиция для вставки
var mid = (left + right) / 2;
var value = collection.ElementAt(mid);
if (value == target)
return mid;
if (value < target)
return BinSearch(collection, target, mid + 1, right);
return BinSearch(collection, target, left, mid - 1);
}
}