This preview shows pages 1–12. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: child. If you encounter a null node reference, replace it with the new node. Try this sequence: Juliet, Tom, Dick, Harry, Romeo add method public void add ( Comparable obj) { Node newNode = new Node(obj); newNode.data = obj; newNode.left = null; newNode.right = null; if (root == null) root = newNode; else root.addNode(newNode); } Node class public void addNode (Node newNode) { int comp = newNode.data.compareTo(data); if (comp < 0) { if (left == null) left = newNode; else left.addNode(newNode); } else if (comp > 0) { if (right == null) right = newNode; else right.addNode(newNode); } } Consider add for two sets of data Random Sorted Which is faster? find method public boolean find (Comparable obj) { Node current = root; while (current != null) { int d= current.data.compareTo(obj); if (d == 0) return true; else if (d > 0) current = current.left; else current = current.right; } return false; }...
View Full
Document
 Spring '08
 MILLER
 Binary Search

Click to edit the document details