Advertisement
nigatigga

Untitled

Oct 24th, 2014
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. Driver:
  2. insert the value into the tree;
  3.  
  4. BTree:
  5. insert the value from root(find the right place to put the value from root to leaf);
  6. if the root splits
  7. create a new parent for the splitted old root;
  8.  
  9. InternalNode:
  10. find the correct child for this value;
  11. insert this value to that child
  12. {
  13. if child is not full and hence, succesfully inserted
  14. return NULL;
  15. else child splitted(update internal node)
  16. {
  17. if internal node is not full
  18. insert the new child;
  19. else
  20. if left sibling is not full
  21. lookLeft(update parent if needed)
  22. else if right sibling is not full
  23. lookRight(update parent if needed)
  24. else
  25. {
  26. split
  27. maintain left right sibling, and parent-child relation
  28. return the new node after split
  29. }
  30. }
  31. }
  32.  
  33. LeafNode:
  34. if Leaf is not full
  35. put the value to the right slot;
  36. //NOTE: if it is the first child of parent, keys[0] of its parent need to be updated
  37. else
  38. {
  39. if left sibling is not full
  40. lookLeft(update parent if needed)
  41. else if right sibling is not full
  42. lookRight(update parent if needed)
  43. else
  44. {
  45. split;
  46. maintain left right sibling, and parent-child relation;
  47. return the new Leaf after split so their parent could update itself;
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement