tree_example.cc

来自「一个德国人Kasper Peeters用C++ template写的tree的S」· CC 代码 · 共 40 行

CC
40
字号
#include <algorithm>#include <string>#include <iostream>#include "tree.hh"using namespace std;int main(int, char **)   {   tree<string> tr;   tree<string>::iterator top, one, two, loc, banana;   top=tr.begin();   one=tr.insert(top, "one");   two=tr.append_child(one, "two");   tr.append_child(two, "apple");   banana=tr.append_child(two, "banana");   tr.append_child(banana,"cherry");   tr.append_child(two, "peach");   tr.append_child(one,"three");   loc=find(tr.begin(), tr.end(), "two");   if(loc!=tr.end()) {      tree<string>::sibling_iterator sib=tr.begin(loc);      while(sib!=tr.end(loc)) {         cout << (*sib) << endl;         ++sib;         }      cout << endl;      tree<string>::iterator sib2=tr.begin(loc);      tree<string>::iterator end2=tr.end(loc);      while(sib2!=end2) {         for(int i=0; i<tr.depth(sib2)-2; ++i)             cout << " ";         cout << (*sib2) << endl;         ++sib2;         }      }   }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?