Skip to content

Commit

Permalink
adding fixes to linear search
Browse files Browse the repository at this point in the history
  • Loading branch information
nkane committed Nov 18, 2018
1 parent 743ee79 commit 5901fb0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
4 changes: 3 additions & 1 deletion algorithms/grokking-algorithms/lib/algorithms.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 6 additions & 4 deletions algorithms/grokking-algorithms/linear_search/src/main.c
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#include <stdio.h>
#include <stdlib.h>
#include <lib/algorithms.c>
#include <assert.h>

#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;
}

0 comments on commit 5901fb0

Please sign in to comment.