diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/tree.c | 19 |
1 files changed, 9 insertions, 10 deletions
@@ -156,22 +156,21 @@ mq_tree_insert_sibling_allocated(MqTree *node, MqTree *sibling, gpointer data) node->root = sibling->root; node->parent = sibling->parent; - /* Link to next sibling, if any. */ - if (sibling->next) { - node->next = sibling->next; - sibling->next->prev = node; + /* Link new node and parent's last child. */ + node->prev = node->parent->last_child; + if (node->prev) { + node->prev->next = node; } - /* Link to previous sibling. */ - node->prev = sibling; - sibling->next = node; + /* Set parent's new last child. */ + node->parent->last_child = node; + + node->position = node->parent->position + node->parent->size - 1; + update_positions(node, 1); node->size = 0; update_sizes(node, 1); - node->position = sibling->position + sibling->size - 1; - update_positions(node, 1); - node->data = data; print_tree("Inserted sibling", node); |