package lab06;
import java.util.*;
public class BTreeClient {
public static void main(String[] args) {
BTree<Integer> testTree = setupTree();
System.out.println("Levelorder tree traversal");
Iterator<Integer> levelOrderIterator = testTree.getLevelOrderIterator();
while( levelOrderIterator.hasNext() )
System.out.print(levelOrderIterator.next()+" ");
System.out.println("\n");
System.out.println("Inorder tree traversal");
Iterator<Integer> inOrderIterator = testTree.getInOrderIterator();
while( inOrderIterator.hasNext() )
System.out.print(inOrderIterator.next()+" ");
System.out.println("\n");
System.out.println("Preorder tree traversal");
Iterator<Integer> preOrderIterator = testTree.getPreOrderIterator();
while( preOrderIterator.hasNext() )
System.out.print(preOrderIterator.next()+" ");
System.out.println("\n");
System.out.println("Postorder tree traversal");
Iterator<Integer> postOrderIterator = testTree.getPostOrderIterator();
while( postOrderIterator.hasNext() )
System.out.print(postOrderIterator.next()+" ");
System.out.println("\n");
}
static BTree<Integer> setupTree(){
BTreeNode<Integer> n6 = new BTreeNode<Integer>(6, null, null);
BTreeNode<Integer> n7 = new BTreeNode<Integer>(7, null, null);
BTreeNode<Integer> n4 = new BTreeNode<Integer>(4, n6, n7);
BTreeNode<Integer> n3 = new BTreeNode<Integer>(3, null, null);
BTreeNode<Integer> n12 = new BTreeNode<Integer>(12, n3, n4);
BTreeNode<Integer> n8 = new BTreeNode<Integer>(8, null, null);
BTreeNode<Integer> n2 = new BTreeNode<Integer>(2, null, n8);
BTreeNode<Integer> n11 = new BTreeNode<Integer>(11, null, null);
BTreeNode<Integer> n5 = new BTreeNode<Integer>(5, n11, n2);
BTreeNode<Integer> n10 = new BTreeNode<Integer>(10, n12, n5);
return new BTree<Integer>(n10);
}
}
|