一个不错的多叉树, stl风格

tree<std::string> tr9;
tree<std::string>::pre_order_iterator iter1;
tr9.set_head("hi");
tr9.insert_after(tr9.begin(), "a");
tr9.insert_after(tr9.begin(), "b");
tr9.append_child(tr9.begin(), "0");
tr9.append_child(tr9.begin().begin(), "0.1");
tr9.append_child(tr9.begin().begin(), "0.0");

iter1 = tr9.begin();
int num1 = iter1.number_of_children();
if (num1 > 0) {
iter1 = tr9.child(iter1, num1 - 1);
if (iter1 == NULL)
XTRACE_RAW(COLOR_BLACK, "null iter?\n");
else
tr9.insert_after(iter1, "2");
} else {
tr9.append_child(tr9.begin(), "1");
}
print_tree(tr9, tr9.begin(), tr9.end());
int depth1 = tr9.depth(tr9.begin());
int depth2 = tr9.depth(tr9.begin().begin());
int size1 = tr9.size();
int size2 = tr9.size(tr9.begin());

tree<std::string> tr;
tree<std::string>::pre_order_iterator html, body, h1, h3, bh1, mv1;

print_tree(tr, tr.begin(), tr.end());

html=tr.insert(tr.begin(), "html");
tr.insert_after(html, "extra");
body=tr.append_child(html, "body");
h1 =tr.append_child(body, "h1");
bh1 = tr.insert_after(h1, "after h1");
auto aa = tr.parent(bh1);
tr.append_child(aa, "some textaaa");
tr.append_child(h1, "some text");
tr.append_child(body, "more text");

print_tree(tr, tr.begin(), tr.end());

XTRACE_RAW(COLOR_BLACK, L"test finish\n");

 

url: http://tree.phi-sci.com/

 

posted on 2017-09-04 19:19  拥剑公子  阅读(227)  评论(0编辑  收藏  举报

导航