Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int maxDepth(node* node,tree *T)
- {
- if (node==T->nulo)
- return 0;
- else{
- /* compute the depth of each subtree */
- int lDepth = maxDepth(node->left,T);
- int rDepth = maxDepth(node->right,T);
- /* use the larger one */
- if (lDepth > rDepth)
- return(lDepth+1);
- else return(rDepth+1);
- }
- }
- void percorreArvoreDm(void *a,void *c,void (*printaSvg)(void*,void*,FILE*,int,int,char,int,int),FILE *arquivoSVG,int tam,int y,int x){
- node *this = (node *)a;
- tree *b = (tree* )c;
- int var;
- if (this->data == b->nulo){
- fprintf(arquivoSVG,"\t<rect x='%d' y='%d' width='%d' height='%d' stroke='%s' fill='%s' stroke-width='%d'/>\n",x-5,y,10,10,"black","black",1);
- fprintf(arquivoSVG,"\t<text x='%d' y='%d' text-anchor='middle' font-size='4px'>%s</text>/>\n",x,y+6,"nil");
- return;
- }
- printaSvg(this->data,this->parent->data,arquivoSVG,x,y,this->color,tam,var);
- fprintf(arquivoSVG,"\t<line x1='%d' y1='%d' x2='%d' y2='%d' stroke-width = '1' fill='black' stroke='black'/>\n",x,y,x-tam/2,y+30);
- percorreArvoreDm(this->left,b,printaSvg,arquivoSVG,tam/2,y+30,x-tam/2);
- fprintf(arquivoSVG,"\t<line x1='%d' y1='%d' x2='%d' y2='%d' stroke-width = '1' fill='black' stroke='black'/>\n",x,y,x+tam/2,y+30);
- percorreArvoreDm(this->right,b,printaSvg,arquivoSVG,tam/2,y+30,x+tam/2);
- }
- void percorreArvoreDmAux(void *a,void (*printaSvg)(void*,void*,FILE*,int,int,char,int,int),FILE *arquivoSVG){
- tree *aux = (tree *)a;
- int f = maxDepth(aux->raiz,aux);
- printf("\ntam:%d\n\n\n",aux->tam);
- int p = pow(2,f);
- int tam = p*20;
- int y = 30;
- int x = tam;
- fprintf(arquivoSVG,"\t<text x='%d' y='%d' text-anchor='middle' font-size='4px'>%s</text>/>\n",x,y,"RAIZ");
- percorreArvoreDm(aux->raiz,aux,printaSvg,arquivoSVG,tam/2,y,x);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement