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

View File

@@ -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;