dsa

Data Structures & Algorithms - Spring 2018
Log | Files | Refs | README

TreeNode.java (1049B)


      1 package lab11;
      2 
      3 class TreeNode<T> {
      4     private T item;
      5     private TreeNode<T> leftChild;
      6     private TreeNode<T> rightChild;
      7 
      8     public TreeNode(T newItem) {
      9         // Initializes tree node with item and no children.
     10         item = newItem;
     11         leftChild  = null;
     12         rightChild = null;
     13     }  // end constructor
     14 
     15     public TreeNode(T newItem,
     16                     TreeNode<T> left, TreeNode<T> right) {
     17         // Initializes tree node with item and
     18         // the left and right children references.
     19         item = newItem;
     20         leftChild  = left;
     21         rightChild = right;
     22     }  // end constructor
     23 
     24     public T getItem()
     25     {return item;}
     26 
     27     public void setItem(T item)
     28     {this.item = item;}
     29 
     30     public TreeNode<T> getLeftChild()
     31     {return leftChild;}
     32 
     33     public void setLeftChild(TreeNode<T> leftChild)
     34     {this.leftChild = leftChild;}
     35 
     36 
     37     public TreeNode<T> getRightChild()
     38     {return rightChild;}
     39 
     40     public void setRightChild(TreeNode<T> rightChild)
     41     {this.rightChild = rightChild;}
     42 
     43 
     44 }  // end TreeNode
     45 
     46