public: // Add public methods.
Error_code search_tree(Record &target);
Error_code insert(const Record &new_entry);
B_tree();
Error_code remove(const Record &target);
private: // data members
B_node<Record, order> *root;
// Add private auxiliary functions here.
Error_code recursive_search_tree(B_node<Record, order> *current, Record &target);
Error_code search_node(B_node<Record, order> *current, const Record &target, int &position);
Error_code push_down(
B_node<Record, order> *current, const Record &new_entry,
Record &median, B_node<Record, order> * &right_branch);
void push_in(B_node<Record, order> *current,
const Record &entry, B_node<Record, order> *right_branch, int position);
void split_node(B_node<Record, order> *current, // node to be split
const Record &extra_entry,B_node<Record, order> *extra_branch,
int position, //index in node whereextra entry goes
B_node<Record, order> * &right_half, Record &median); // new node for right half of entries
}
1.搜索不成功是的position恰好是插入时的position.
2.result = push_down(root, new_entry, median, right_branch); 若result==overflow,则一定是要长出新根。否则会回溯到上一层,然后插入上面的某一层。
3对于
.push_down(
B_node<Record, order> *current, const Record &new_entry,
Record &median, B_node<Record, order> * &right_branch)中的
if (current == NULL) {
// Since we cannot insert in an empty tree, the recursion terminates.
median = new_entry;
right_branch = NULL;
result = overflow;
} 在每一轮插入时都会执行,并且是在递归到NULL节点时。这时的overflow代表的是已经递归到要插入的位置了。
4.对于有效的插入来说,程序总是在
if (current->count < order-1) {
result = success;
push_in(current, extra_entry, extra_branch, position);
}
这里结束的。