0

We have a class project to implement an AVL tree. Here are two very general implementations:

template<class T>
class AVLTree {
  int key;
  int height;
  int BF;
  T data;
  AVLTree<T>* father, leftSon, rightSon;
.
.
.
}

A friend told me I really should use Nodes but he wasn't able to explain why. So here is the second implementation which I have seen in many places (using Node):

template<class T>
class AVLTree {
  int key;
  int height;
  int BF;
  T data;
  Node* father, leftSon, rightSon;

  class Node {
    int key;
    int height;
    int BF;
    T data;
    Node* father, leftSon, rightSon;
  }
.
.
.
}

What's really the difference? Is my implementation impossible in terms of the compiler?

dlvhdr
  • 482
  • 4
  • 19
  • In the second version, you should not have three Node* variables in the AVLTree - just one (for the root node). – davmac Oct 24 '13 at 11:13

1 Answers1

1

Technically, you are right and nodes are not necessary, though remember C++ is an OOP language, and the object you want is an AVLTree, which is consisted of nodes.

Ariel Pinchover
  • 654
  • 3
  • 17