




Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





public static final boolean contains(Comparable item, Comparable[] array,int n) { int low = 0; int high = n-1; while (low <= high) { int mid = (low+high) / 2; int compare = item.compareTo(array[mid]); if (compare < 0) { high = mid – 1; } else if (compare > 0) { low = mid + 1; } else { return true; } } return false; }
coldplay busted pink madonna U macy gray shakira LHS: value is “smaller” RHS: value is “larger” The concepts of “smaller” and “larger” are defined according to the data you are processing …
class EmptyTree extends SearchTree { protected boolean isEmpty() {} public boolean isEmpty() { return true; } … more methods } class NodeTree extends SearchTree { private Comparable data; private SearchTree left; private SearchTree right; protected NodeTree(Comparable item) { data = item; left = empty(); right = empty(); } public boolean isEmpty() { return false; } … more methods }