MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / BinSearch

Function BinSearch

Arrays/31_Menu_for_Array.c:184–211  ·  view source on GitHub ↗

Binary Search Normal method Function

Source from the content-addressed store, hash-verified

182
183//Binary Search Normal method Function
184void BinSearch(struct array *arr,int key)
185{
186 int low=0;
187 int high=arr->length-1;
188 int mid,x=0;
189 while(low<=high)
190 {
191 mid=(low+high)/2;
192 if(arr->A[mid]==key)
193 {
194 printf("The element is found at index %d",mid);
195 x=1;
196 break;
197 }
198 else if(key<arr->A[mid])
199 {
200 high=mid-1;
201 }
202 else if(key>arr->A[mid])
203 {
204 low=mid+1;
205 }
206 }
207 if(x==0)
208 {
209 printf("The element is not found\n");
210 }
211}
212
213//Binary Search Recursion method Function
214void RevBinSearch(struct array arr,int low,int high,int key)

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected