Thursday, June 22, 2023

binary search alternative

#include <iostream>

#include <vector>


using namespace std;


int main()

{

    int array[] = { 1,3,3,4,5,5,6,9,10,12,12,15 };

    int n = sizeof(array) / sizeof(int);

    int k = 0;

    int x = 3;


    for (int b = n / 2; b >= 1; b /= 2)

    {

        while (k + b < n && array[k + b] <= x)

        {

            k += b;

        }

    }

    

    if (array[k] == x)

    {

        int a = 10;

    }

}


No comments:

Post a Comment

Task in UnrealEngine

 https://www.youtube.com/watch?v=1lBadANnJaw