Sentinel search: Remove bounds check (fixes #887) (#888)

... which is the entire point of sentinel search
This commit is contained in:
Lars Müller 2021-10-17 02:28:37 +02:00 committed by GitHub
parent 654105c8ef
commit ce3f01f54c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -41,11 +41,9 @@ int sentinel_linear_search( int arr[], int len, int key ){
int temp = arr[len-1]; int temp = arr[len-1];
arr[len-1] = key; arr[len-1] = key;
int i; int i = 0;
for(i=0;arr[len-1]!=arr[i];i++){ while (arr[len-1] != arr[i]) {
if(i==len-1){ i++;
break;
}
} }
arr[len-1] = temp; arr[len-1] = temp;