释放树中的节点
Freeing a node in a tree
这是一道概念题。我想从树中删除一个特定的节点,这意味着我释放了这个特定的节点并将其设置为空。我是否需要将其父节点的子指针也设置为空,因为它不会有子指针,或者将释放原始节点并将其设置为自由无论如何将父节点的下一个指针设置为空?
Do I need to make its parent node's child pointer also set to null since it won't have a child pointer
是的,这是应用程序级逻辑,因此必须由实现树的人(您)处理。
will freeing the original node and setting it to free anyway set the next pointer of the parent node to null?
没有。另请注意,调用 free
不会将传递的指针设置为 NULL。因此,最好在调用 free
.
之后这样做
这是一道概念题。我想从树中删除一个特定的节点,这意味着我释放了这个特定的节点并将其设置为空。我是否需要将其父节点的子指针也设置为空,因为它不会有子指针,或者将释放原始节点并将其设置为自由无论如何将父节点的下一个指针设置为空?
Do I need to make its parent node's child pointer also set to null since it won't have a child pointer
是的,这是应用程序级逻辑,因此必须由实现树的人(您)处理。
will freeing the original node and setting it to free anyway set the next pointer of the parent node to null?
没有。另请注意,调用 free
不会将传递的指针设置为 NULL。因此,最好在调用 free
.