Binary Search Normal method Function
| 182 | |
| 183 | //Binary Search Normal method Function |
| 184 | void 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 |
| 214 | void RevBinSearch(struct array arr,int low,int high,int key) |