# Java general tree



## Robbpell (Jul 23, 2007)

Not sure if you guys help with this sort of stuff but im doing a project for school and i need some help. 

<Java>
<compiling with netbeans>
<school>

1. i have the algorithm for the add left most child but idk what value to give the search method (what is the root value)

2. the search method has errors (missing return statement) how can i change my search to return a value in both situations even though its a recursive call.



```
package generaltree;

/**
 *
 * @author Robb
 */
public class Tree {
private char dData;
private Tree LMC;
private Tree RS; // right sibling

public Tree(char dd){
dData = dd;
LMC = null;
RS = null;

}

public void addLMC(char parent, char child)
{   // Create new node using the child as the value.
    Tree newNode = new Tree(child);
    
    //Traverse the tree until you find value parent.
    
    //If parent doesn't have left child add newNode as its left child.
    
    //If parent has left child change newNode's RS to old LMC 
    
    //change parents LMC to newNode.

    }

public void preOrder(Tree node){
    System.out.println(node.dData);
    
    if (node.LMC != null){
        preOrder(node.LMC);
        Tree temp = node;
        while (temp.RS != null){
            preOrder(temp.RS);
            temp = temp.RS;
        }
    }
}

public Tree search(Tree node, char dd){
 if (node.dData == dd ){
       return node;
   }  
   else if (node.LMC != null){
            if (node.LMC.dData == dd ){
            return node.LMC;
            }
        search(node.LMC, dd);
        Tree temp = node;
        while (temp.RS != null){
            search(temp.RS, dd);
            temp = temp.RS;
        }
    }
   else return null;
}


}
```


----------

