Advertisement
Guest User

Untitled

a guest
Nov 11th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. int maxDepth(ramo* node,tree_t *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),FILE *arquivoSVG,int tam,int y,int x){
  17. ramo *this = (ramo *)a;
  18. tree_t *b = (tree_t* )c;
  19. //int var = 0;
  20. if (this->data == b->nulo){
  21. 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);
  22. return;
  23. }
  24. 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);
  25. printaSvg(this->data,this->parent->data,arquivoSVG,x,y,this->cor,tam);
  26. percorreArvoreDm(this->left,b,printaSvg,arquivoSVG,tam/2,y+30,x-tam/2);
  27. 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);
  28. percorreArvoreDm(this->right,b,printaSvg,arquivoSVG,tam/2,y+30,x+tam/2);
  29. }
  30. void arqpercorreArvoreDmAux(void *a,void (*printaSvg)(void*,void*,FILE*,int,int,char,int),FILE *arquivoSVG){
  31. tree_t *aux = (tree_t *)a;
  32. int f = maxDepth(aux->root,aux);
  33. //printf("\ntam:%d\n\n\n",aux->tama);
  34. int p = pow(2,f);
  35. int tam = p*20;
  36. int y = 30;
  37. int x = tam;
  38. fprintf(arquivoSVG,"\t<text x='%d' y='%d' text-anchor='middle' font-size='4px'>%s</text>\n",x,y,"RAIZ");
  39. percorreArvoreDm(aux->root,aux,printaSvg,arquivoSVG,tam/2,y,x);
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement