From 70aa23d950f3c132c991671e3530689dcd2de224 Mon Sep 17 00:00:00 2001 From: muniyagoyal <56516947+muniyagoyal@users.noreply.github.com> Date: Sun, 13 Oct 2019 23:42:23 +0530 Subject: [PATCH] updates with the if codes --- linearSearch.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/linearSearch.py b/linearSearch.py index 496a5ba..2c5aded 100644 --- a/linearSearch.py +++ b/linearSearch.py @@ -16,9 +16,18 @@ def func(arr,n, x): n = len(arr) result = func(arr, n,x) +if(arr[mid] == x): + return mid -if (result==-1): - print("value",x," not found in array") + #if not and value is greater than mid value ignore left part and increase its value + elif arr[mid] < x: + l = mid+1 + + + # if value less than mid value ignore right part and decrease right value by -1 + else: + r= mid-1 + else: print("value found here:",result)