Beispiel #1
0
static node tree2list(node *root)
{
    node *alist,*blist;
    if(root == NULL)return NULL;
    alist = tree2list(root->left);
    blist = tree2list(root->right);
    root->left = root;
    root->right = root;
    alist = append(alist , root);
    blist = append(alist , blist);
    return alist;
}
string tree2string(TreeNode* root){
	list<string> L=tree2list(root);
	string s;
	while(!L.empty()){
		s+=L.front()+" ";
		L.pop_front();
	}
	return s;
}
Beispiel #3
0
int main()
{
    node *root = create(4);
    insert_node(&root,2);
    insert_node(&root,1);
    insert_node(&root,3);
    insert_node(&root,6);
    insert_node(&root,5);
    insert_node(&root,7);
    node head = tree2list(root);
    return 0;
}
Beispiel #4
0
  //---:---<*>---:---<*>---:---<*>---:---<*>---:---<*>---:---<*>---: 
  void tree2list(tree &A,iterator_t n,
		 list<elem_t> &L,elem_t BP,elem_t EP) {
    if (n == A.end()) return;
    iterator_t c = n.lchild();
    if (c == A.end()) {
      L.insert(L.end(),A.retrieve(n)); 
    } else {
      L.insert(L.end(),BP); 
      L.insert(L.end(),A.retrieve(n)); 
      while (c != A.end()) {
	tree2list(A,c,L,BP,EP);
	c = c.right();
      }
      L.insert(L.end(),EP);
    }
  }
Beispiel #5
0
 //---:---<*>---:---<*>---:---<*>---:---<*>---:---<*>---:---<*>---: 
 void tree2list(tree &A,list<elem_t> &L,elem_t BP,elem_t EP) {
   tree2list(A,A.begin(),L,BP,EP);
 }