BST recursion on getting range values
807589Sep 30 2008 — edited Sep 30 2008+++Hi,+++
+++I'm doing my project on BST on getting range values from Nodes and store it in ArrayList. Im stuck in some particular areas specially in recursion for adding val+ues+.+My algorithm is I find the minimum node and once I know its location I traverse from it up to the maximum range and add the values while traversing. The problem arises during traversal.could anyone help PLEASE my inOrderAdd method is not adding the right range values.
My code goes like this
myListOfValues= new ArrayList();
public List<V> getValues(K rangeMin, K rangeMax)
{
Node<K,V> startRange=findMinRange(root,rangeMin);
inOrderAdd(startRange,rangeMax);
return myListOfValues;
*} //THIS IS WHERE MY PROBLEM IS*
private List<V> inOrderAdd(Node<K,V>startRange, K rangeMax)
{ {
int compareNum=startRange.getKey().compareTo(rangeMax);//becomes null somehow
//base cases
if (startRange.getKey()==rangeMax)
myListOfValues.add(startRange.getValue());
if (startRange.getLeft()==null && startRange.getRight()==null)
myListOfValues.add(startRange.getValue());
//recursion starts
if (compareNum<0){
if(startRange.getParent()!=null){
inOrderAdd(startRange.getParent(),rangeMax);}
if(startRange.getRight()!=null){
inOrderAdd(startRange.getRight(),rangeMax);
if(startRange.getLeft()!=null){
inOrderAdd(startRange.getRight(),rangeMax);}
}
}}
return myListOfValues;
}