diff options
-rw-r--r-- | src/tree.c | 22 |
1 files changed, 15 insertions, 7 deletions
@@ -190,16 +190,24 @@ mq_tree_remove_allocated(MqTree *node) { MqTree *child; - /* Link siblings and/or parent to children (may be NULL). */ + /* Link siblings to children or each other. */ if (node->prev) { - node->prev->next = node->first_child; - } else { - node->parent->first_child = node->first_child; + node->prev->next = node->first_child ? + node->first_child : node->next; } if (node->next) { - node->next->prev = node->last_child; - } else { - node->parent->last_child = node->last_child; + node->next->prev = node->last_child ? + node->last_child : node->prev; + } + + /* Update parent's links. */ + if (node->parent->first_child == node) { + node->parent->first_child = node->first_child ? + node->first_child : node->next; + } + if (node->parent->last_child == node) { + node->parent->last_child = node->last_child ? + node->last_child : node->prev; } /* Link children to siblings (may be NULL). */ |