帮看看我这先序遍历怎么写??谢谢
源程序如下:
//二叉树查找 插入 显示
class Node{
int iData;
double fData;
Node leftChild;
Node rightChild;
public void displayNode(){
//
System.out.println( "{ ");
System.out.println(iData);
System.out.println( ", ");
System.out.println(fData);
System.out.println( "} ");
}
}//end Node
class Tree{
private Node root;//
//public Node root;//
//public void find(int key){//不可以用void
public Node find(int key){
//
Node current =root;
while(current.iData !=key){
if(key <current.iData)
current =current.leftChild;
else current =current.rightChild;
if (current ==null)
return null;
}
return current;
}
public void insert(int id,double dd){
//
Node newNode =new Node();
newNode.iData =id;
newNode.fData =dd;
if(root ==null) root =newNode;
else {
Node current =root;
Node parent;
while(true){
parent =current;
if(id <current.iData){//go left
current =current.leftChild;
if (current ==null){//if end of the line
parent.leftChild=newNode;
return;
}
}//end go left
//}//end while
else{ //go right
current =current.rightChild;
if(current ==null){//if end of the line
parent.rightChild=newNode;
return;
}//end if end of the line
}//end go right
}//
}
}//end insert
public void delete(int id){
//public boolean delete(int key){
//code too more
}
//}
///*
private void preOrder(Node localRoot){//递归先续遍历 ????
if (localRoot!=null){
System.out.println(localRoot.fData+ " ");//打印出先序的树出来???
preOrder(localRoot.leftChild);
preOrder(localRoot.rightChild);
}
}
//*/
}//end Tree
class TreeApp{