public class BitNode {
String data;
BitNode lchild;
BitNode rchild;
public void setNode(String data, BitNode lc, BitNode rc) {
this.data = data;
lchild = lc;
rchild = rc;
}
static int counter = 0;
public BitNode createBiTree(BitNode root, String[] a, int i) {
if (i < a.length) {
BitNode lchild = new BitNode();
BitNode rchild = new BitNode();
root.data = a[i];
root.lchild = createBiTree(lchild, a, ++counter);
root.rchild = createBiTree(rchild, a, ++counter);
}
return root;
}
public void PreOrder(BitNode node) {
if (node != null) {
System.out.print(node.data);
PreOrder(node.lchild);
PreOrder(node.rchild);
}
}
public void PreOrder1(BitNode root){
Stack<BitNode> stack=new Stack();
if(root!=null){
stack.push(root);
}
while (!stack.empty()){
BitNode node=stack.pop();
System.out.print(node.data);
if (node.rchild!=null) stack.push(node.rchild);
if (node.lchild!=null) stack.push(node.lchild);
}
}
public void AfeOrder(BitNode node) {
if (node != null) {
AfeOrder(node.lchild);
AfeOrder(node.rchild);
System.out.print(node.data);
}
}
public void zxOrder(BitNode node){
if(node!=null){
zxOrder(node.lchild);
System.out.print(node.data);
zxOrder(node.rchild);
}
}
public void zzOrderfDiGui(BitNode node){
Stack<BitNode> stack=new Stack<BitNode>();
while (node!=null || !stack.isEmpty()){
while (node!=null){
stack.push(node);
node=node.lchild;
}
if(!stack.isEmpty()){
BitNode node1=stack.pop();
System.out.print(node1.data);
node1=node1.rchild;
}
}
}
public void ccOrder(BitNode root){
Queue<BitNode> queue =new ArrayDeque<BitNode>();
if (root !=null) queue.offer(root);
while (!queue.isEmpty()){
BitNode node =queue.poll();
System.out.print(node.data);
if (node.lchild!=null) queue.offer(node.lchild);
if (node.rchild!=null) queue.offer(node.rchild);
}
}