1
1
Fork 0

Фикс форматирования кода

Co-Authored-By: Eugene Kortov <kortovea@gmail.com>
This commit is contained in:
Arthur 2020-02-21 17:16:38 +03:00 committed by Enchased Horse
parent 182827bfc2
commit 4641b59de9
1 changed files with 37 additions and 1 deletions

38
jcf.md
View File

@ -612,7 +612,43 @@ PhantomReference при вызове метода `get()` возвращает
Пример кода двоичного поиска:
```java
package test2;
public class Q {
public static void main(String[] args) {
Q q = new Q();
q.binSearch();
}
private void binSearch() {
int[] inpArr = {1, 2, 3, 4, 5, 6, 7, 8, 9};
Integer result = binSearchF(inpArr, 1, 0, inpArr.length - 1);
System.out.println("-----------------------");
result = binSearchF(inpArr, 2, 0, inpArr.length - 1);
System.out.println("Found at position " + result);
}
private Integer binSearchF(int[] inpArr, int searchValue, int low, int high) {
Integer index = null;
while (low <= high) {
System.out.println("New iteration, low = " + low + ", high = " + high);
int mid = (low + high) / 2;
System.out.println("trying mid = " + mid + " inpArr[mid] = " + inpArr[mid]);
if (inpArr[mid] < searchValue) {
low = mid + 1;
System.out.println("inpArr[mid] (" + inpArr[mid] + ") < searchValue(" + searchValue + "), mid = " + mid
+ ", setting low = " + low);
} else if (inpArr[mid] > searchValue) {
high = mid - 1;
System.out.println("inpArr[mid] (" + inpArr[mid] + ") > searchValue(" + searchValue + "), mid = " + mid
+ ", setting high = " + high);
} else if (inpArr[mid] == searchValue) {
index = mid;
System.out.println("found at index " + mid);
break;
}
}
return index;
}
}
import java.util.HashMap;
import java.util.IdentityHashMap;