From ea8888d0468b6ca159b634e67f131980cd742ffc Mon Sep 17 00:00:00 2001 From: Arthur Date: Fri, 21 Feb 2020 17:24:18 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=20=D1=84=D0=BE=D1=80?= =?UTF-8?q?=D0=BC=D0=B0=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=BA=D0=BE=D0=B4=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jcf.md | 72 +++++++++++++++++++++++++++++----------------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/jcf.md b/jcf.md index fd92ed4..7d9034c 100644 --- a/jcf.md +++ b/jcf.md @@ -656,52 +656,52 @@ import java.util.Map; public class Q { - public static void main(String[] args) { + public static void main(String[] args) { - Q q = new Q(); - q.binSearch(); + Q q = new Q(); + q.binSearch(); - } + } - private void binSearch() { + private void binSearch() { - int inpArr[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + 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); + 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); + System.out.println("Found at position " + result); - } + } - private Integer binSearchF(int inpArr[], int searchValue, int low, int high) { + 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); + 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]); + 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; - } + 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; - } + return index; + } } ``` @@ -827,8 +827,8 @@ for (int i = 0; i < list.size(); i++) { ```java int i = 0; while (i < list.size()) { - //list.get(i); - i++; + //list.get(i); + i++; } ``` @@ -836,7 +836,7 @@ while (i < list.size()) { ```java for (String element : list) { - //element; + //element; } ```