设为首页 加入收藏

TOP

基于顺序存储的多叉树实现: (5) 兄弟遍历 (二)
2014-11-23 22:57:49 来源: 作者: 【 】 浏览:7
Tags:基于 顺序 存储 实现 兄弟
template
3 inline mtree::sibling_iterator_impl::sibling_iterator_impl()
4 :base_type()
5 {
6 }
7 template
8 template
9 inline mtree::sibling_iterator_impl::sibling_iterator_impl(const base_type& iter)
10 :base_type(iter)
11 {
12 if (!iter.is_null())
13 {
14 node_pointer_type p_node = &(*tree_)[off_];
15 p_node->parent_ root_ = off_ - p_node->parent_: root_ = tree_->size();
16 }
17
18 }
在上面有参构造函数中,如果结点非空,会计算保存其父结点的偏移量,存于成员变量root_中,如果不存在父结点(当为根结点时),root_等于size()。
(6)公有方法的实现,代码如下:
1 template
2 template
3 inline typename mtree::template sibling_iterator_impl&
4 mtree::sibling_iterator_impl::operator++()
5 {
6 increment(typename reverse_trait::type());
7 return *this;
8 }
9 template
10 template
11 inline typename mtree::template sibling_iterator_impl&
12 mtree::sibling_iterator_impl::operator--()
13 {
14 decrement(typename reverse_trait::type());
15 return *this;
16 }
17 template
18 template
19 inline typename mtree::template sibling_iterator_impl
20 mtree::sibling_iterator_impl::operator++(int)
21 {
22 sibling_iterator_impl iter(*this);
23 ++(*this);
24 return iter;
25 }
26 template
27 template
28 inline typename mtree::template sibling_iterator_impl
29 mtree::sibling_iterator_impl::operator--(int)
30 {
31 sibling_iterator_impl iter(*this);
32 --(*this);
33 return iter;
34 }
35 template
36 template
37 inline typename mtree::template sibling_iterator_impl
38 mtree::sibling_iterator_impl::operator + (size_t off)
39 {
40 sibling_iterator_impl iter(*this);
41 iter += off;
42 return iter;
43 }
44 template
45 template
46 inline typename mtree::template sibling_iterator_impl&
47 mtree::sibling_iterator_impl::operator += (size_t off)
48 {
49 while (off)
50 {
51 if (base_type::is_null()) break;
52 ++(*this); --off;
53 }
54 return *this;
55 }
56 template
57 template
58 inline typename mtree::template sibling_iterator_impl
59 mtree::sibling_iterator_impl::operator - (size_t off)
60 {
61 sibling_iterator_impl iter(*this);
62 iter -= off;
63 return iter;
64 }
65 template
66 template
67 inline typename mtree::template sibling_iterator_impl&
68 mtree::sibling_iterator_impl::operator -= (size_t off)
69 {
70 while (off)
71 {
72 if (base_type::is_null()) break;
73 --(*this); --off;
74 }
75 return *this;
76 }
77 template
78 template
79 inline typename mtree::template sibling_iterator_impl
80 mtree::sibling_iterator_impl::begin() const
81 {
82 sibling_iterator_impl iter(*this);
83 iter.first(typename reverse_trait::type());
84 return iter;
85 }
86 template
87 template
88 inline typename mtree::template sibling_iterator_impl
89 mtree::sibling_iterator_impl::end() const
90 {
91 sibling_iterator_impl iter(*this);
92 if (tree_)
93 {
94 iter.off_ = tree_->size();
95 }
96 return iter;
97 }
首页 上一页 1 2 3 下一页 尾页 2/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇读入文件时最后一次重复 下一篇简易位图内存管理器的设计

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: