Sha256: cb95a6cf0f1b52d11cddbbd487b223a593f819b75ad6170ad1f4860cae2157b0

Contents?: true

Size: 482 Bytes

Versions: 395

Compression:

Stored size: 482 Bytes

Contents

#include "binary_search.h"

int *binary_search(const int value, const int *arr, const size_t length)
{
   if (0 == length || NULL == arr) {
      return NULL;
   }
   const int *low = arr;
   const int *high = arr + length - 1;
   while (low <= high) {
      const int *mid = low + (high - low) / 2;
      if (*mid > value) {
         high = mid - 1;
      } else if (*mid < value) {
         low = mid + 1;
      } else {
         return (int *)mid;
      }
   }
   return NULL;
}

Version data entries

395 entries across 395 versions & 1 rubygems

Version Path
trackler-2.2.1.98 tracks/c/exercises/binary-search/src/example.c
trackler-2.2.1.97 tracks/c/exercises/binary-search/src/example.c
trackler-2.2.1.96 tracks/c/exercises/binary-search/src/example.c
trackler-2.2.1.95 tracks/c/exercises/binary-search/src/example.c
trackler-2.2.1.94 tracks/c/exercises/binary-search/src/example.c
trackler-2.2.1.93 tracks/c/exercises/binary-search/src/example.c
trackler-2.2.1.92 tracks/c/exercises/binary-search/src/example.c
trackler-2.2.1.91 tracks/c/exercises/binary-search/src/example.c
trackler-2.2.1.90 tracks/c/exercises/binary-search/src/example.c
trackler-2.2.1.89 tracks/c/exercises/binary-search/src/example.c
trackler-2.2.1.88 tracks/c/exercises/binary-search/src/example.c
trackler-2.2.1.87 tracks/c/exercises/binary-search/src/example.c
trackler-2.2.1.86 tracks/c/exercises/binary-search/src/example.c
trackler-2.2.1.85 tracks/c/exercises/binary-search/src/example.c
trackler-2.2.1.84 tracks/c/exercises/binary-search/src/example.c
trackler-2.2.1.83 tracks/c/exercises/binary-search/src/example.c
trackler-2.2.1.82 tracks/c/exercises/binary-search/src/example.c
trackler-2.2.1.81 tracks/c/exercises/binary-search/src/example.c
trackler-2.2.1.80 tracks/c/exercises/binary-search/src/example.c
trackler-2.2.1.79 tracks/c/exercises/binary-search/src/example.c