【问题标题】:AVL Tree implementation with nodes or without nodes带节点或不带节点的 AVL 树实现
【发布时间】: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* 变量——只有一个(用于根节点)。

标签: c++ nodes avl-tree


【解决方案1】:

从技术上讲,您是对的,节点不是必需的,但请记住 C++ 是一种 OOP 语言,而您想要的对象是由节点组成的 AVLTree。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多