[Глава 4] Упражнения 1-4

This commit is contained in:
Пытков Роман
2025-07-26 17:46:42 +03:00
parent 1f144231c0
commit 83d5f60fe9
8 changed files with 72 additions and 3 deletions

View File

@@ -0,0 +1,16 @@
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);
}
}