KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > TestBinTree


1 import ro.infoiasi.donald.compiler.simple.*;
2 import java.util.*;
3
4 public class TestBinTree {
5     public static void printBinTree(Iterator it) {
6         while (it.hasNext()) {
7             Integer JavaDoc i = (Integer JavaDoc)(((BinTreeNode)(it.next())).get());
8             System.out.print(i+" ");
9         }
10         System.out.println();
11     }
12     public static void main(String JavaDoc args[]) {
13         BinTree t = new BinTree();
14         BinTreeNode n0 = t.addRoot(new Integer JavaDoc(0));
15         BinTreeNode n1 = t.addLeftChild(new Integer JavaDoc(1), n0);
16         BinTreeNode n2 = t.addLeftChild(new Integer JavaDoc(2), n1);
17         BinTreeNode n3 = t.addLeftChild(new Integer JavaDoc(3), n2);
18         BinTreeNode n4 = t.addRightChild(new Integer JavaDoc(4), n1);
19         BinTreeNode n5 = t.addRightChild(new Integer JavaDoc(5), n0);
20         
21         printBinTree(t.preIterator());
22         printBinTree(t.inIterator());
23         printBinTree(t.postIterator());
24         System.out.println("size: "+t.size());
25
26         t.removeNode(n3);
27         System.out.println("size: "+t.size());
28         t.removeNode(n0);
29         System.out.println("size: "+t.size());
30     }
31 }
32
Popular Tags