aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-01-21 09:07:41 +0100
committerMattias Andrée <maandree@operamail.com>2014-01-21 09:07:41 +0100
commit29711149e3210b1b02637a51e6258cdc600934f1 (patch)
treebce9233161e6980aa545a7640bcf5b843f59346d
parentadd binary search (diff)
downloadalgorithms-and-data-structures-29711149e3210b1b02637a51e6258cdc600934f1.tar.gz
algorithms-and-data-structures-29711149e3210b1b02637a51e6258cdc600934f1.tar.bz2
algorithms-and-data-structures-29711149e3210b1b02637a51e6258cdc600934f1.tar.xz
m fix in binary search
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r--src/algorithms/searching/BinarySearch.java4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/algorithms/searching/BinarySearch.java b/src/algorithms/searching/BinarySearch.java
index 150cca9..a72f75f 100644
--- a/src/algorithms/searching/BinarySearch.java
+++ b/src/algorithms/searching/BinarySearch.java
@@ -168,6 +168,7 @@ public class BinarySearch
if (item == (x = array[mid = (min + max) >>> 1]))
£{2};
+ /* NB! (x R item), instead of (item R x) */
if (£(${3} x item)) min = mid + 1;
else max = mid - 1;
@@ -192,6 +193,7 @@ public class BinarySearch
£>fi
}
+ /* NB! (x R item), instead of (item R x) */
if (£(${1} x item)) min = mid + 1;
else max = mid - 1;
@@ -223,8 +225,8 @@ public class BinarySearch
£>}
if (order == SortOrder.ASCENDING)
-£>_ 'greater'
£>_ 'less'
+£>_ 'greater'
}
£>done
}