From 29711149e3210b1b02637a51e6258cdc600934f1 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 21 Jan 2014 09:07:41 +0100 Subject: m fix in binary search MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/algorithms/searching/BinarySearch.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 } -- cgit v1.2.3-70-g09d2