4 {
5 node_pointer_type p_node = &(*tree_)[off_];
6 while (off_!=root_&&p_node->parent_&&!p_node->next_sibling_)
7 {
8 off_ -= p_node->parent_;
9 p_node = &(*tree_)[off_];
10 }
11 if (off_==root_||!p_node->parent_)
12 {
13 off_ = tree_->size();
14 return;
15 }
16 off_ += p_node->next_sibling_; p_node = &(*tree_)[off_];
17 while (p_node->first_child_)
18 {
19 off_ += p_node->first_child_;
20 p_node = &(*tree_)[off_];
21 }
22 }
(4)forward_prev:求正向前一个叶子,步骤如下:1) 如果当前结点不是子树根结点且存在父亲但没有左兄弟,那么就一直向上回溯直到结点为子树根结点或不存在父亲或存在左兄弟为止,反之转到2)。2) 如果当前结点是子树根结点或没有父亲,那么返回end,否则转到3)。3) 这时存在左兄弟,那么沿该左兄弟的最后一个孩子一直向下搜索直到没有孩子结点为止,代码如下:
1 template
2 template
3 inline void mtree
4 {
5 node_pointer_type p_node = &(*tree_)[off_];
6 while (off_!=root_&&p_node->parent_&&!p_node->prev_sibling_)
7 {
8 off_ -= p_node->parent_;
9 p_node = &(*tree_)[off_];
10 }
11 if (off_==root_||!p_node->parent_)
12 {
13 off_ = tree_->size();
14 return;
15 }
16 off_ -= p_node->prev_sibling_; p_node = &(*tree_)[off_];
17 while (p_node->last_child_)
18 {
19 off_ += p_node->last_child_;
20 p_node = &(*tree_)[off_];
21 }
22 }
(5)构造函数的实现,代码如下:
1 template
2 template
3 inline mtree
4 :base_type()
5 {
6 root_ = 0;
7 }
8 template
9 template
10 inline mtree
11 :base_type(iter)
12 {
14 }
(6)公有方法的实现,代码如下:
1 template
2 template
3 inline typename mtree
4 mtree
5 {
6 increment(typename reverse_trait
7 return *this;
8 }
9 template
10 template
11 inline typename mtree
12 mtree
13 {
14 decrement(typename reverse_trait
15 return *this;
16 }
17 template
18 template
19 inline typename mtree
20 mtree
21 {
22 leaf_iterator_impl
23 ++(*this);
24 return iter;
25 }
26 template
27 template
28 inline typename mtree
29 mtree
30 {
31 leaf_iterator_impl
32 --(*this);
33 return iter;
34 }
35 template
36 template
37 inline typename mtree
38 mtree
39 {
40 leaf_iterator_impl
41 iter += off;
42 return iter;
43 }
44 template
45 template
46 inline typename mtree
47 mtree
48 {
49 while (off)
50 {
51 if (base_type::is_null()) break;
52 ++(*this); --off;
53