public class BST {
  int value; 
  BST left; 
  BST right; 
}

--

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop\c212 11-04
> BST a = new BST()
> a
BST@7b1f6cf8
> a.value
0
> a.left
null
> a.right
null


--

-bash-4.2$ pwd
/nobackup/dgerman/vivek
-bash-4.2$ ls -ld BST*.java
-rw-r--r-- 1 dgerman faculty  912 Nov  3 07:05 BST.java
-rw-r--r-- 1 dgerman faculty 1172 Jul  6 20:34 BSTNode.java
-bash-4.2$ javac *.java
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
-bash-4.2$ java BST
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
Enter the numbers in your tree (bye to stop).
Enter: 10
The tree becomes:
  10
Enter: 6
The tree becomes:
     10
   +--+
   6
Enter: 8
The tree becomes:
           10
      +-----+
      6
      +--+
         8
Enter: 7
The tree becomes:
                       10
            +-----------+
            6
            +-----+
                  8
               +--+
               7
Enter: 5
The tree becomes:
                       10
            +-----------+
            6
      +-----+-----+
      5           8
               +--+
               7
Enter: bye
-bash-4.2$

--

public class BST {
  int value; 
  BST left; 
  BST right; 
  public BST(int value, BST left, BST right) {
    this.value = value; 
    this.left = left; 
    this.right = right; 
  }
  public void insert(int value) {
    if (value == this.value) {
      // nothing  
    } else if (value < this.value) { 
      if (this.left == null) {
        this.left = new BST(value, null, null);  
      } else this.left.insert(value); // structural recursion 
    } else { // if (value > this.value) {
      if (this.right == null) {
        this.right = new BST(value, null, null);  
      } else this.right.insert(value); // structural recursion 
    }
      
  }
  public void show() {
    System.out.print( "(" + this.value + " "); 
    if (this.left != null) 
      this.left.show(); 
    else 
      System.out.print( this.left + " "); 
    if (this.right != null) 
      this.right.show();     
    else 
      System.out.print( this.right + " "); 
    System.out.print(") "); 
  }
  public static void main(String[] args) {
    BST a = new BST(5, null, null); // (5 null null)
    a.left = new BST(3, null, null); // (5 (3 null null) null)
    a.left.right = new BST(4, null, null); // (5 (3 null (4 null null)) null)
    a.show(); // --> (5 (3 null (4 null null)) null)
    System.out.println("\n----------------------"); 
    BST b =  new BST(5, null, null); 
    b.insert(3); 
    b.insert(4); 
    b.show(); // (5 (3 null (4 null null)) null)
    System.out.println("\n----------------------"); 
    BST c = null; 
    System.out.println("Start with nothing: " + c); 
    c = new BST(10, null, null); // first insert is a constructor  
    System.out.print("Insert 10, tree now: "); c.show(); System.out.println(); c.insert(6);
    System.out.print("Insert  6, tree now: "); c.show(); System.out.println(); c.insert(8); 
    System.out.print("Insert  8, tree now: "); c.show(); System.out.println(); c.insert(7);
    System.out.print("Insert  7, tree now: "); c.show(); System.out.println(); c.insert(5);
    System.out.print("Insert  5, tree now: "); c.show(); System.out.println();
  }
}

--

Welcome to DrJava.  Working directory is C:\Users\dgerman\Desktop\c212 11-04
> run BST
(5 (3 null (4 null null ) ) null ) 
----------------------
(5 (3 null (4 null null ) ) null ) 
----------------------
Start with nothing: null
Insert 10, tree now: (10 null null ) 
Insert  6, tree now: (10 (6 null null ) null ) 
Insert  8, tree now: (10 (6 null (8 null null ) ) null ) 
Insert  7, tree now: (10 (6 null (8 (7 null null ) null ) ) null ) 
Insert  5, tree now: (10 (6 (5 null null ) (8 (7 null null ) null ) ) null ) 


--

-bash-4.2$ ls
BST.class  BSTNode.class  EmptyBST.class  meeting2           TreePrinter.java
BST.java   BSTNode.java   EmptyBST.java   TreePrinter.class  TreePrinter$PrintableNode.class
-bash-4.2$ cd meeting2/
-bash-4.2$ ls
AVL.java  Pair.java  TreePrinter.java
-bash-4.2$ javac *.java
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
Note: AVL.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
-bash-4.2$ java AVL
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
Enter the numbers for your red black search tree:
10
6
8
7
5
bye
               8.0
        ┌───────┴───────┐
       6.0            10.1
    ┌───┴───┐
   5.1     7.1
-bash-4.2$ java AVL
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
Enter the numbers for your red black search tree:
10
bye
  10.1
-bash-4.2$ java AVL
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
Enter the numbers for your red black search tree:
10
6
bye
Print, I'm entering the abstract method
      10.0
    ┌───┘
   6.1
-bash-4.2$ java AVL
Picked up _JAVA_OPTIONS: -Xms512m -Xmx512m
Enter the numbers for your red black search tree:
10
6
8
bye
       8.0
    ┌───┴───┐
   6.1    10.1
-bash-4.2$

--