简体   繁体   中英

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

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++?

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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