//---:---<*>---:---<*>---:---<*>---:---<*>---:---<*>---:---<*>---: void mirror(tree_t &T,node_t n) { list< tree<int> > L; node_t c = n.lchild(); if (c==T.end()) return; while (c!=T.end()) { printf("passing to list subtree rooted at %d\n",*c); L.insert(L.begin(),tree_t()); tree_t &Q = *L.begin(); T.splice(Q.begin(),c); #if 0 cout << "T: \n"; T.lisp_print(); cout << "\nQ: \n"; Q.lisp_print(); cout << endl; #endif mirror(Q); c = n.lchild(); } c = n.lchild(); while (!L.empty()) { tree_t &Q = *L.begin(); printf("passing to tree subtree rooted at %d\n",*Q.begin()); c = T.splice(c,Q.begin()); c++; L.erase(L.begin()); } }
//---:---<*>---:---<*>---:---<*>---:---<*>---:---<*> void split_down(tree<int> &T,node_t p,int n,int g) { // Si el valor en la raiz esta OK, entonces no hace falta // hacer nada. if (*p <= n) return; // Llama a `distrib()' para ver como es la distribucion // del valor en el nodo `*p' vector<int> v; distrib(*p,g,v); // Va iterando, creando los nuevos nodos node_t c = p.lchild(); for (unsigned int j=0; j<v.size(); j++) { c = T.insert(c,v[j]); // Aplica recursivamente la funcion split_down(T,c++,n,g); } }