diff --git a/searching/sentinel_linear_search.c b/searching/sentinel_linear_search.c index bec8a6d8..43def0e3 100644 --- a/searching/sentinel_linear_search.c +++ b/searching/sentinel_linear_search.c @@ -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;