java dsf搜索,

package suanfa;

import java.util.Random;

public class Nodesearch {
    int len=0;
	public void dfs(Node node,int value){
		int a[]=new int[1000];
		if(node==null){
			System.out.print("this is the empty tree!");
		}
		if(node.getLchild()==null&&node.getRchild()==null){
			if(node.getValue()!=value){
				return;
			}
			else{
				System.out.println("A path find:");
				for(int i=0;i=node.getValue()){
			if(node.getRchild()==null){
				Node nodenew=new Node();
				nodenew.setValue(value);
				node.setRchild(nodenew);
			}
			else{
				insert(node.getRchild(),value);
			}
		}
		else{
			if(node.getLchild()==null){
				Node nodenew=new Node();
				nodenew.setValue(value);
				node.setLchild(nodenew);
			}
			else{
				insert(node.getLchild(),value);
			}
		}
	}
}

 node类是:

package suanfa;

public class Node {
   
	private int value;
	private Node lchild;
	private Node rchild;
	public int getValue() {
		return value;
	}
	public Node getLchild() {
		return lchild;
	}
	public Node getRchild() {
		return rchild;
	}
	public void setValue(int value) {
		this.value = value;
	}
	public void setLchild(Node lchild) {
		this.lchild = lchild;
	}
	public void setRchild(Node rchild) {
		this.rchild = rchild;
	}
	
}

 

你可能感兴趣的:(java)