Advertisement
Guest User

doideradoida

a guest
Sep 23rd, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.91 KB | None | 0 0
  1. struct No{
  2.   int numero;
  3.   struct No *esquerda;
  4.   struct No *direita;
  5. };
  6. typedef struct No No;
  7.  
  8. //Criar Arvore
  9.  
  10. void CriarArvore(No **pRaiz)
  11. {
  12.   *pRaiz = NULL;
  13. }
  14.  
  15. //Contar Nos
  16.  
  17. int ContarNos(No *pRaiz){
  18.   if(pRaiz == NULL){
  19.     return 0;
  20.   }
  21.   else{
  22.     return 1 + ContarNos(pRaiz->esquerda) + ContarNos(pRaiz->Direita);
  23.   }
  24. }
  25.  
  26. //Contar Folhas
  27.  
  28. int ContarFolhas(No *pRaiz){
  29.   if(pRaiz == NULL){
  30.     return 0;
  31.   }
  32.   if(pRaiz->esquerda == NULL && pRaiz->direita == NULL){
  33.     return 1;
  34.   }
  35.   return contarFolhas(pRaiz->esquerda) + contarFolhas(pRaiz->direita);
  36. }
  37.  
  38. //Altura da Arvore
  39.  
  40. int maior(int a,int b){
  41.   if (a > b){
  42.     return a;
  43.   }else{
  44.     return b;
  45.   }
  46. }//Maior
  47.  
  48. int altura(No *pRaiz){
  49.   if((pRaiz == NULL) || (pRaiz->esquerda == NULL && pRaiz->direita == NULL)){
  50.     return 0;
  51.   }else{
  52.     return 1 + maior(altura(pRaiz->esquerda),altura(pRaiz->direita));
  53.   }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement