int find (int [] a, int n) { int left = 1; int right = n ; int mid = ⌊ (left + right)/2 ⌋ ; while (left <= right) { if (a[mid]==mid) return mid; if (a[mid]> mid) right = mid – 1; else left = mid + 1; } return 0; }
B.
int find (int [] a, int n) { int left = 1; int right = n ; while (left < right) { int mid=⌊ (left + right)/2 ⌋ ; if (a[mid]==mid) return mid; if (a[mid]> mid) right = mid – 1; else left = mid + 1; } return 0; }
C.
int find (int [] a, int n) { int left = 1; int right = n ; while (left <= right) { if (a[mid]==mid) return mid; if (a[mid]> mid) right = mid – 1; else left = mid + 1; int mid = ⌊ (left + right)/2 ⌋ ; } return 0; }
D.
int find (int [] a, int n) { int left = 1; int right = n ; while (left <= right) { int mid=⌊ (left + right)/2 ⌋ ; if (a[mid]==mid) return mid; if (a[mid]> mid) right = mid – 1; else left = mid + 1; } return 0; }