Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int maxDepth(ramo* node,tree_t *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),FILE *arquivoSVG,int tam,int y,int x){
- ramo *this = (ramo *)a;
- tree_t *b = (tree_t* )c;
- //int var = 0;
- if (this->data == b->nulo){
- fprintf(arquivoSVG,"<rect x=\"%d\" y=\"%d\" width=\"10\" height=\"10\" stroke=\"black\" fill-opacity='1' fill=\"black\" stroke-width=\"1.0\"/>",x-5,y);
- return;
- }
- fprintf(arquivoSVG,"\t<line x1='%d' y1='%d' x2='%d' y2='%d' stroke-width = '2' fill='black' stroke='black'/>\n",x,y,x-tam/2,y+30);
- printaSvg(this->data,this->parent->data,arquivoSVG,x,y,this->cor,tam);
- 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 = '2' 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 arqpercorreArvoreDmAux(void *a,void (*printaSvg)(void*,void*,FILE*,int,int,char,int),FILE *arquivoSVG){
- tree_t *aux = (tree_t *)a;
- int f = maxDepth(aux->root,aux);
- //printf("\ntam:%d\n\n\n",aux->tama);
- 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->root,aux,printaSvg,arquivoSVG,tam/2,y,x);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement