简体   繁体   English

如何在c ++中实现一个avl树,每个节点都是另一个avl树

[英]How to implement an avl tree in c++ with each node being another avl tree

I Have an input.txt file which contains number like this: input.txt file 我有一个input.txt文件,其中包含这样的数字: input.txt文件

I am trying to make an avl tree in which every node is a number form the first column and each of these nodes point to another avl tree containing numbers from the second column.Could someone explain how to implement this in c++? 我正在尝试制作一个avl树,其中每个节点都是第一列中的一个数字,并且每个节点都指向另一个包含第二列中的数字的avl树。有人可以解释如何在c ++中实现它吗?

Implement this as you would with an integer node: 就像使用整数节点那样实现:

struct AVL_node
{
  bool color;
  int key;
  AVL_Tree value;
  AVL_Node * left_subtree;
  AVL_Node * right_subtree;
};

In a tree, you need to separate the key, value and link fields. 在树中,您需要分隔键,值和链接字段。 The key is what you are using for ordering the nodes. 关键是用于订购节点的密钥。 The value is the data. 该值是数据。

The value doesn't make a difference. 该值没有影响。 It could be std::vector or std::map or missing. 它可能是std::vectorstd::map或丢失。 Nodes in general are not copied, only the links change. 通常不复制节点,仅更改链接。 However, if a node is copied, both the key and value fields are copied. 但是,如果复制节点,则键和值字段都将被复制。

Remembering, when organizing nodes, only the link fields change. 请记住,在组织节点时,只有链接字段会更改。 The key is used to determine ordering. 该键用于确定顺序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM