File tree Expand file tree Collapse file tree
src/main/java/com/thealgorithms/searches Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -29,24 +29,24 @@ public final class IterativeBinarySearch implements SearchAlgorithm {
2929 */
3030 @ Override
3131 public <T extends Comparable <T >> int find (T [] array , T key ) {
32- int l ;
33- int r ;
34- int k ;
35- int cmp ;
32+ int left ;
33+ int right ;
34+ int mid ;
35+ int comparison ;
3636
37- l = 0 ;
38- r = array .length - 1 ;
37+ left = 0 ;
38+ right = array .length - 1 ;
3939
40- while (l <= r ) {
41- k = (l + r ) >>> 1 ;
42- cmp = key .compareTo (array [k ]);
40+ while (left <= right ) {
41+ mid = (left + right ) >>> 1 ;
42+ comparison = key .compareTo (array [mid ]);
4343
44- if (cmp == 0 ) {
45- return k ;
46- } else if (cmp < 0 ) {
47- r = --k ;
44+ if (comparison == 0 ) {
45+ return mid ;
46+ } else if (comparison < 0 ) {
47+ right = --mid ;
4848 } else {
49- l = ++k ;
49+ left = ++mid ;
5050 }
5151 }
5252
You can’t perform that action at this time.
0 commit comments