Created
December 7, 2012 21:32
-
-
Save bilalq/4236704 to your computer and use it in GitHub Desktop.
Someone's BST homework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class BinarySearchTree extends BinaryTree | |
{ | |
public void insert(Comparable item) | |
{ | |
if (getRoot() == null) | |
setRoot(new TreeNode(item)); | |
else | |
{ | |
TreeNode p, q = null; | |
q = getRoot(); | |
while (q != null) | |
{ | |
p = q; | |
if (item.compareTo(p.getValue()) < 0) | |
q = p.getLeft(); | |
else | |
q = p.getRight(); | |
} | |
} | |
if (item.compareTo(p.getValue()) < 0) | |
p.setLeft(new TreeNode(item)); | |
else | |
p.setRight(new TreeNode(item)); | |
} | |
public TreeNode find(Comparable key) { | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment