一个不错的多叉树, 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/
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战