J
jason_box
I have this generic class that stores a bstnode:
public class BST_Node<K extends Comparable<? super K>,E>
{
private BST_Node<K,E> left;
private BST_Node<K,E> right;
private K key;
private E elem;
public BST_Node(K k, E e)
{
key = k;
elem = e;
left = null;
right = null;
}
............
general get/set methods
}
I'm having some problems in the main BST Class to actually insert a
node based on the key.
public class BSTOBJ<K extends Comparable<? super K>,E>
{
private BST_Node<K,E> root;
public BSTOBJ()
{
root = null;
}
public boolean isEmptyOBJ()
{
return (root == null);
}
public E searchNode(K key)
{
E temp = null;
return temp;
}
public void insertNode(K key, E elem)
{
BST_Node<K,E> node = new BST_Node<K,E>(key,elem);
//if root doesn't hold the key
if(root.searchNode(key) != root.getElem())
{
//i was thinking of generating the new object of type BST_NODE
//use the compareTO operator to check if th current root holds
the value
//theres a search(K key) which returns back an E object if it
exists already in the
//tree, i wanted the insert to be done iteravtively
}
}
if anyone could help me with this method that would be great. thank you
public class BST_Node<K extends Comparable<? super K>,E>
{
private BST_Node<K,E> left;
private BST_Node<K,E> right;
private K key;
private E elem;
public BST_Node(K k, E e)
{
key = k;
elem = e;
left = null;
right = null;
}
............
general get/set methods
}
I'm having some problems in the main BST Class to actually insert a
node based on the key.
public class BSTOBJ<K extends Comparable<? super K>,E>
{
private BST_Node<K,E> root;
public BSTOBJ()
{
root = null;
}
public boolean isEmptyOBJ()
{
return (root == null);
}
public E searchNode(K key)
{
E temp = null;
return temp;
}
public void insertNode(K key, E elem)
{
BST_Node<K,E> node = new BST_Node<K,E>(key,elem);
//if root doesn't hold the key
if(root.searchNode(key) != root.getElem())
{
//i was thinking of generating the new object of type BST_NODE
//use the compareTO operator to check if th current root holds
the value
//theres a search(K key) which returns back an E object if it
exists already in the
//tree, i wanted the insert to be done iteravtively
}
}
if anyone could help me with this method that would be great. thank you