diff --git a/algorithms/grokking-algorithms/lib/algorithms.c b/algorithms/grokking-algorithms/lib/algorithms.c index 24666dc..de3c341 100644 --- a/algorithms/grokking-algorithms/lib/algorithms.c +++ b/algorithms/grokking-algorithms/lib/algorithms.c @@ -34,9 +34,11 @@ Linear_Search_Int(int *buffer, int size, int search) Start_Time = clock(); int i; int found = 0; + int guess = 0; for (i = 0; i < size; i++) { - if (*(buffer + i) == search) + guess = *(buffer + i); + if (guess == search) { found = 1; break; diff --git a/algorithms/grokking-algorithms/linear_search/src/main.c b/algorithms/grokking-algorithms/linear_search/src/main.c index 3113c36..274b9be 100644 --- a/algorithms/grokking-algorithms/linear_search/src/main.c +++ b/algorithms/grokking-algorithms/linear_search/src/main.c @@ -1,16 +1,18 @@ #include #include #include +#include -#define SIZE 100000000 -#define FIND 99999999 +#define SIZE 100 +#define FIND 99 int main() { int *x = (int *)malloc(sizeof(int) * SIZE); - Generate_Array_Data_Int(x, len(x)); - Linear_Search_Int(x, SIZE, FIND); + Generate_Array_Data_Int(x, SIZE); + int found = Linear_Search_Int(x, SIZE, FIND); + assert(found == 1); free(x); return 0; }