Advertisement
Guest User

Untitled

a guest
Nov 12th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. int maxDepth(node* node,tree *T)
  2. {
  3. if (node==T->nulo)
  4. return 0;
  5. else{
  6. /* compute the depth of each subtree */
  7. int lDepth = maxDepth(node->left,T);
  8. int rDepth = maxDepth(node->right,T);
  9.  
  10. /* use the larger one */
  11. if (lDepth > rDepth)
  12. return(lDepth+1);
  13. else return(rDepth+1);
  14. }
  15. }
  16. void percorreArvoreDm(void *a,void *c,void (*printaSvg)(void*,void*,FILE*,int,int,char,int,int),FILE *arquivoSVG,int tam,int y,int x){
  17. node *this = (node *)a;
  18. tree *b = (tree* )c;
  19. int var;
  20. if (this->data == b->nulo){
  21. 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);
  22. fprintf(arquivoSVG,"\t<text x='%d' y='%d' text-anchor='middle' font-size='4px'>%s</text>/>\n",x,y+6,"nil");
  23. return;
  24. }
  25. printaSvg(this->data,this->parent->data,arquivoSVG,x,y,this->color,tam,var);
  26. 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);
  27. percorreArvoreDm(this->left,b,printaSvg,arquivoSVG,tam/2,y+30,x-tam/2);
  28. 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);
  29. percorreArvoreDm(this->right,b,printaSvg,arquivoSVG,tam/2,y+30,x+tam/2);
  30. }
  31. void percorreArvoreDmAux(void *a,void (*printaSvg)(void*,void*,FILE*,int,int,char,int,int),FILE *arquivoSVG){
  32. tree *aux = (tree *)a;
  33. int f = maxDepth(aux->raiz,aux);
  34. printf("\ntam:%d\n\n\n",aux->tam);
  35. int p = pow(2,f);
  36. int tam = p*20;
  37. int y = 30;
  38. int x = tam;
  39. fprintf(arquivoSVG,"\t<text x='%d' y='%d' text-anchor='middle' font-size='4px'>%s</text>/>\n",x,y,"RAIZ");
  40. percorreArvoreDm(aux->raiz,aux,printaSvg,arquivoSVG,tam/2,y,x);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement