B_tree的分析

class B_tree {
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);

这里结束的。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值