Skip to content

Instantly share code, notes, and snippets.

@bilalq
Created December 7, 2012 21:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bilalq/4236704 to your computer and use it in GitHub Desktop.
Save bilalq/4236704 to your computer and use it in GitHub Desktop.
Someone's BST homework
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