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.