【发布时间】:2013-04-18 13:38:21
【问题描述】:
我们有一个类项目来实现 AVL 树。 下面是两个非常通用的实现:
template<class T>
class AVLTree {
int key;
int height;
int BF;
T data;
AVLTree<T>* father, leftSon, rightSon;
.
.
.
}
一位朋友告诉我我真的应该使用 Nodes,但他无法解释原因。 所以这是我在很多地方看到的第二个实现(使用 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;
}
.
.
.
}
真正的区别是什么?就编译器而言,我的实现是不可能的吗?
【问题讨论】:
-
在第二个版本中,AVLTree 中不应有三个 Node* 变量——只有一个(用于根节点)。