Methods for designing general Tree nodes

Source: Internet
Author: User
I learned a method today.
Struct Node
{
Address_t m_prev,
Address_t m_next,
Address_t m_data
};

Address_t is actually an address, which can be defined as follows:
# Define address_t unsigned long
In addition, address_t can be changed to offset_t, indicating the offset for a certain position.

The address is saved in the node. When a node is used, the value of the memory unit pointed to by the node is actually obtained. Then, you can perform a forced conversion based on the desired type.

For example, if the address stored in a node points to the long type
Node * pnode = NULL;
/* Get pnode */
...

Long ltmp = * (long *) (pnode-> m_data );

However, it is actually more complicated.
For example, it is possible that the node does not store the address, but the offset of a base address. However, the principle is the same.

In this case, the person who designs the tree only needs to consider the implementation of the tree.AlgorithmInstead of storing data in the node of the tree. You can store things in the tree as needed.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.