From cf6215df42e48dbb88855c1fb57b68738e40e12e Mon Sep 17 00:00:00 2001 From: Misha Date: Tue, 30 Sep 2025 15:11:09 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B8=D1=82=D1=8C=20bS?= =?UTF-8?q?earch.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bSearch.cpp | 74 ----------------------------------------------------- 1 file changed, 74 deletions(-) delete mode 100644 bSearch.cpp diff --git a/bSearch.cpp b/bSearch.cpp deleted file mode 100644 index 990732f..0000000 --- a/bSearch.cpp +++ /dev/null @@ -1,74 +0,0 @@ -#include -#include -using namespace std; - -void bSort(int arr[], int size) { - for (int i = 0; i < size - 1; ++i) { - for (int j = 0; j < size - i - 1; ++j) { - if (arr[j] > arr[j + 1]) { - int temp = arr[j]; - arr[j] = arr[j + 1]; - arr[j + 1] = temp; - } - } - } -} - -int bSearch(int arr[], int size, int target) { - int low = 0; - int high = size - 1; - - while (low <= high) { - int m = low + (high - low) / 2; - - if (arr[m] == target) { - return m; - } - else if (arr[m] < target) { - low = m + 1; - } - else { - high = m - 1; - } - } - - return -1; -} - -int main() { - srand(time(0)); - setlocale(0, ""); - - const int size = 10; - int arr[size]; - - cout << "Початковий масив: "; - for (int i = 0; i < size; ++i) { - arr[i] = rand() % 300 + 1; - cout << arr[i] << " "; - } - cout << endl; - - bSort(arr, size); - - cout << "Вiдсортований масив: "; - for (int i = 0; i < size; ++i) { - cout << arr[i] << " "; - } - cout << endl; - - int t; - cout << "Введiть елемент для пошуку: "; - cin >> t; - - int index = bSearch(arr, size, t); - - if (index != -1) { - cout << "Елемент знайдено на iндексi (у вiдсортованому масивi): " << index << endl; - } - else { - cout << "Елемент не знайдено." << endl; - } - - return 0; -} \ No newline at end of file