Skip to content

Commit

Permalink
Sentinel search: Remove bounds check (fixes #887) (#888)
Browse files Browse the repository at this point in the history
... which is the entire point of sentinel search
  • Loading branch information
appgurueu authored Oct 17, 2021
1 parent 654105c commit ce3f01f
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions searching/sentinel_linear_search.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,9 @@ int sentinel_linear_search( int arr[], int len, int key ){
int temp = arr[len-1];
arr[len-1] = key;

int i;
for(i=0;arr[len-1]!=arr[i];i++){
if(i==len-1){
break;
}
int i = 0;
while (arr[len-1] != arr[i]) {
i++;
}

arr[len-1] = temp;
Expand Down

0 comments on commit ce3f01f

Please sign in to comment.