Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
84 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include "tree.hh" | ||
#include <iostream> | ||
|
||
// This example shows how to iterate over the head nodes | ||
// of a tree only. | ||
|
||
int main(int, char **) | ||
{ | ||
tree<std::string> t; | ||
|
||
t.set_head("one"); | ||
auto i2 = t.insert(t.end(), "two"); | ||
auto i3 = t.insert(t.end(), "three"); | ||
t.append_child(i2, "apple"); | ||
t.append_child(i2, "pear"); | ||
t.append_child(i3, "banana"); | ||
t.append_child(i3, "kiwi"); | ||
|
||
tree<std::string>::sibling_iterator it=t.begin(); | ||
while(it!=t.end()) | ||
std::cerr << (*it++) << std::endl; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include <iostream> | ||
#include "tree.hh" | ||
#include "tree_util.hh" | ||
|
||
void print_tree(const tree<std::string>& tr) | ||
{ | ||
tree<std::string>::pre_order_iterator it = tr.begin(); | ||
tree<std::string>::pre_order_iterator end = tr.end(); | ||
if(!tr.is_valid(it)) return; | ||
int rootdepth=tr.depth(it); | ||
std::cout << "-----" << std::endl; | ||
while(it!=end) { | ||
for(int i=0; i<tr.depth(it)-rootdepth; ++i) | ||
std::cout << " "; | ||
std::cout << (*it) << std::endl << std::flush; | ||
++it; | ||
} | ||
std::cout << "-----" << std::endl; | ||
} | ||
|
||
int main(int, char **) | ||
{ | ||
tree<std::string> my_tree; | ||
|
||
tree<std::string>::iterator iA = my_tree.insert(my_tree.end(), "A"); | ||
tree<std::string>::iterator iB = my_tree.insert(my_tree.end(), "B"); | ||
tree<std::string>::iterator iB1 = my_tree.append_child(iB, "B1"); | ||
tree<std::string>::iterator iC = my_tree.insert(my_tree.end(), "C"); | ||
print_tree(my_tree); | ||
|
||
my_tree.move_after(iB1, iC); | ||
print_tree(my_tree); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters