Advertisement
gracefu

Untitled

Oct 10th, 2016
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. while (node != NULL) {
  2. if (key < node->key) {
  3. // Insert in left subtree
  4. FastIndexTreeNode *&insertin = node->left;
  5. } else if (key > node->key) {
  6. // Insert in right subtree
  7. FastIndexTreeNode *&insertin = node->right;
  8. } else {
  9. // key == node->key. Stop here.
  10. return node;
  11. }
  12. // Insert in the subtree
  13. if (insertin == NULL) {
  14. // We've reached a leaf node
  15. FastIndexTreeNode *insert = new FastIndexTreeNode(key, node);
  16. insertin = insert;
  17. this->updatecounts(node, 1);
  18. this->insertbalance(insert, -1);
  19. return insert;
  20. } else {
  21. // Recurse
  22. node = insertin;
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement