二叉树(留着用)

package yfTest.shixi;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.SortedSet;

import org.junit.Test;

import sun.misc.Compare;

public class BTree {
	public BTNode root;

	private char[] c = {'a','b','#','c','#','d'} ;
	public static int count = 0;


	public void init(){
		root =new BTNode(getC());
		create(root,c);
	}
	public void create(BTNode node,char[] c){
		char temp ;
		node.addLeft(temp=getC());
		if(temp != '#'){
			create(node.getLeftChild(),c);
		}
		node.addRight(temp=getC());
		if(temp != '#'){
			create(node.getRightChild(),c);
		}
	}
	public char getC(){
		if(BTree.count<c.length)
			return c[BTree.count++];
		return '#';
	}
	@Override
	public String toString(){
		return root.toString();
	}
	@Test
	public void show(){
		init();
		System.out.println(root);
		
		Set<Integer> set = new HashSet<Integer>();
		set.add(123);
		set.add(123);
		int[] a ={123,23,43};
		System.out.println(set);
	}
	@Test
	public void regexTest(){
		String str = "I,.;am;.!;.!;.!eating;.?something";
		str=str.replaceAll("\\p{Punct}", " ");
		System.out.println(str);
	}
}
class BTNode{
	public static int Ceng = 1;
	private char name;
	private BTNode leftChild;
	private BTNode rightChild;
	
	public BTNode(char name){
		this.name = name;
	}
	public boolean hasLeft(){
		return leftChild != null /*&& !leftChild.getName().equals("#")*/;
	}
	public boolean hasRight(){
		return rightChild != null /*&& !leftChild.getName().equals("#")*/;
	}
	public BTNode addLeft(char left){
		leftChild = new BTNode(left);
		return leftChild;
	}
	public BTNode addRight(char right){
		rightChild = new BTNode(right);
		return rightChild;
	}
	public void init(){
		
	}
	@Override
	public String toString(){
		String temp = name+""+BTNode.Ceng+"|";
		BTNode.Ceng++;
		if(hasLeft()) temp+="L "+leftChild.toString();
		if(hasRight()) temp+="R "+rightChild.toString();
		BTNode.Ceng--;
		return temp;
	}
	

	public char getName() {
		return name;
	}
	public BTNode getLeftChild() {
		return leftChild;
	}
	public BTNode getRightChild() {
		return rightChild;
	}
}

你可能感兴趣的:(java,C++,c,JUnit,C#)