From ce3f01f54cef3ebcbde78a9a1c090c2ce0397eaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20M=C3=BCller?= <34514239+appgurueu@users.noreply.github.com> Date: Sun, 17 Oct 2021 02:28:37 +0200 Subject: [PATCH] Sentinel search: Remove bounds check (fixes #887) (#888) ... which is the entire point of sentinel search --- searching/sentinel_linear_search.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) 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;