View Javadoc

1   package baseCode.dataStructure.tree;
2   
3   /***
4    * <hr>
5    * <p>
6    * Copyright (c) 2004 Columbia University
7    * 
8    * @author Paul Pavlidis
9    * @version $Id: BinaryTree.java,v 1.1 2004/07/29 08:38:49 pavlidis Exp $
10   */
11  public class BinaryTree {
12  
13     BinaryTreeNode root;
14  
15     public BinaryTree( BinaryTreeNode root ) {
16        this.root = root;
17     }
18  
19     /***
20      * @return Returns the root.
21      */
22     public BinaryTreeNode getRoot() {
23        return root;
24     }
25  
26     /***
27      * @param root The root to set.
28      */
29     public void setRoot( BinaryTreeNode root ) {
30        this.root = root;
31     }
32  
33     /***
34      * 
35      */
36     public BinaryTree() {
37        super();
38        // TODO Auto-generated constructor stub
39     }
40  
41     public void insertLeft( BinaryTreeNode p, Object o ) {
42        if ( ( p != null ) && ( p.getLeft() == null ) )
43              p.setLeft( new BinaryTreeNode( o ) );
44     }
45  
46     public void insertRight( BinaryTreeNode p, Object o ) {
47        if ( ( p != null ) && ( p.getRight() == null ) )
48              p.setRight( new BinaryTreeNode( o ) );
49     }
50  
51     public BinaryTreeNode getLeft() {
52        if ( !isEmpty() ) return root.getLeft();
53        return null;
54     }
55  
56     public BinaryTreeNode getRight() {
57        if ( !isEmpty() ) return root.getRight();
58        return null;
59     }
60  
61     public boolean isEmpty() {
62        return getRoot() == null;
63  
64     }
65  
66  }