previous | start | next

BST class

The declaration of a generic binary search tree symbol table class should declare the generic parameters, Key and Value, so that elements of type Key are Comparable:

Non-static inner Node class
public class BST<Key extends Comparable<Key>, Value>
{

  private Node root;

  private class Node
  {
    private Key key;
    private Value val;
    private Node left;
    private Node right;
  
    public Node(Key k, Value v)
    {
      key = k;
      val = v;
      left = right = null;
    }

    public Node()
    {
      this(null);
    }     
  }
}


previous | start | next