00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef tree_util_hh_
00024 #define tree_util_hh_
00025
00026 #include <iostream>
00027 #include <string>
00028 #include "tree.h"
00029
00030 namespace kptree {
00031
00032
00033
00034
00035 template<class T>
00036 void print_tree_bracketed(const tree<T>& t, std::ostream& str)
00037 {
00038 int headCount = t.number_of_siblings(t.begin());
00039 int headNum = 0;
00040 for(typename tree<T>::sibling_iterator iRoots = t.begin(); iRoots != t.end(); iRoots++) {
00041 print_subtree_bracketed(t,iRoots,str,"");
00042 if (headNum <= headCount - 1) {
00043 str << std::endl;
00044 }
00045 }
00046 }
00047
00048
00049
00050 template<class T>
00051 void print_subtree_bracketed(const tree<T>& t, typename tree<T>::iterator iRoot, std::ostream& str, std::string padding = "")
00052 {
00053 if(t.empty()) return;
00054 if (t.number_of_children(iRoot) == 0) {
00055 str << padding << *iRoot << std::endl;
00056 }
00057 else {
00058
00059 str << padding << *iRoot << std::endl;
00060
00061 int siblingNum;
00062 typename tree<T>::sibling_iterator iChildren;
00063 for (iChildren = t.begin(iRoot), siblingNum = 0; iChildren != t.end(iRoot); ++iChildren) {
00064
00065 print_subtree_bracketed(t,iChildren,str, padding + " ");
00066
00067 }
00068 }
00069 }
00070 }
00071
00072 #endif