How to call the generic comparable in a AVL Tree descendants class?

23 Views Asked by At

I am attempting to create a AVL Tree implementation. I am working on a method to ocunt the descendants of a node. I also use the comparator.

public class AVLTree<E extends Comparable<E>> implements AVLTreeAPI<E>
{
private Comparator<? super E> cmp; 
public AVLTree(Comparator<? super E> fn)
   {
       root = null;
       count = 0;
       cmp = fn;
   }
  public int descendants(E entry) throws AVLTreeException
   {
      if(entry == null){
         throw new AVLTreeException("Empty tree."); 
      }

      int leftCount = 0;
      int rightCount = 0;

      if (entry.left != null) {
         leftCount = descendants(root.left);
      }

     if (entry.right != null) {
      rightCount = descendants(root.right);
      }
      
      int total = (leftCount + rightCount) + 1;
      return total+1;
   }

I suspect I am using the generic class with "E" inncorrectly. However, I am not sure what to pass into the recursive(or initiial) calls.

0

There are 0 best solutions below