mardi 9 mai 2017

How to design a general Node for a Binary Search Tree?

I'm writing a BinarySearchTree class, that contains methods like add, search, etc., such that different implementations of trees (like AvlTree, RedBlackTree or 2-3Tree) inherit from BinarySearchTree Class. I want to write a general Node class, that all those who use the BinarySearchTree could use. My problem is: different Trees require different variables in the Node class in order to maintain efficiency. AvlTree need a height variable, RedBlackTree need a color variable (which an AvlTree have no use for). What's the best design solution:

  1. declare many variables in the Node (color, height, balancing factor,...), and just give many constructors?
  2. Have a a variable of type Object in Node, called metadata, which every implementation will use to contain its metadata?
  3. Something else?

Aucun commentaire:

Enregistrer un commentaire