Advertisement
dicamarques

Freq2016-P1

Jun 20th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.10 KB | None | 0 0
  1. int contarfolhas(NO *F){
  2.     if(!F)
  3.     return 0;
  4.  
  5.     if(!F->esq && !F->dir)
  6.         return 1;
  7.    
  8.     return contarfolhas(F->esq) + contarfolhas(F->dir);
  9. }
  10.  
  11.  
  12. int EFolha(NO *F){
  13.     if(!F)
  14.         return 0;
  15.     if(!F->esq && !F->dir)
  16.         return 1;
  17.     else
  18.         return 0;
  19. }
  20.  
  21. int contarPREFolhas(NO *F){
  22.     if(!F)
  23.     return 0;
  24.     int contar = 0;
  25.     if( EFolha(F->esq) || EFolha(F->dir))
  26.         contar++;
  27.    
  28.     return contar + contarPREFolhas(F->dir) + contarPREFolhas(F->esq);
  29. }
  30.  
  31.  
  32. int alturaDaArvore(NO *F){
  33.     if(!F)
  34.         return 0;
  35.     if( !F->esq && !F->dir)
  36.         return 1;
  37.     if(alturaDaArvore(F->Esq) > alturaDaArvore(F->Dir)){
  38.         return 1+alturaDaArvore(F->Esq);
  39.     }
  40.     else
  41.         return 1+alturaDaArvore(F->Dir);
  42. }
  43. typedef struct{
  44.     float NotaAluno;
  45.     char NomeAluno[69];
  46.     NO_Lista *Seguinte;
  47. }NO_Lista;
  48. typedef struct{
  49.     int NumAlunos;
  50.     NO_Lista *Topo;
  51. }Lista;
  52.  
  53. typedef struct{
  54.     int Nota;
  55.     Lista *LNomes;
  56. }NO_Hashin;
  57.  
  58. typedef struct{
  59.     NO_Hashin Vector[21]; //0-20 vlaores
  60. }Hashin;
  61.  
  62. int MaisNota(Hashin *Tabela)
  63. {
  64.     if(!Tabela)
  65.         return 0;
  66.     int MaisNota = 0;
  67.     int aux = 0;
  68.    
  69.     for(int i = 0; i<20;i++){
  70.         if(Tabela.Vector[i].LNomes->NumAlunos > aux){
  71.             MaisNota = Tabela.Vector[i].Nota;
  72.             aux = Tabela.Vector[i].LNomes->NumAlunos;
  73.         }
  74.     }
  75.     return MaisNota;
  76. }
  77. void RecolocarAluno(NO_Lista *Ant, NO_Lista *Recolocar, NO_Lista *Topo){
  78.     if(!Ant || !Recolocar)
  79.         return;
  80.     Ant->Seguinte = Recolocar->Seguinte;
  81.    
  82.     if(!Topo){
  83.         Topo = Recolocar;
  84.         Recolocar->Seguinte = NULL;
  85.         return;
  86.     }
  87.    
  88.     NO_Lista *aux = Topo;
  89.     while(aux->Seguinte){
  90.         aux = aux->Seguinte;
  91.     }
  92.     aux->Seguinte = Recolocar;
  93.     Recolocar->Seguinte = NULL;
  94. }
  95.  
  96.  
  97. void ReduzirChumbos(Hashin *Tabela){
  98.     if(!Tabela)
  99.         return;
  100.    
  101.     NO_Lista aux = ant = NULL;
  102.  
  103.     for(int i = 8;i<10;i++){
  104.         aux = ant = Tabela.Vector[i].LNomes->Topo
  105.         while(aux){
  106.             if(aux->NotaAluno > 8.5 && aux->NotaAluno < 9.5 )
  107.                 aux->NotaAluno += 0.3;
  108.            
  109.             if(aux->NotaAluno>=i+1){
  110.                 RecolocarAluno(ant,aux,Tabela.Vector[i+1].LNomes->Topo);
  111.                 Tabela.Vector[i].LNomes->NumAlunos--;
  112.                 Tabela.Vector[i+1].LNomes->NumAlunos++;
  113.             }
  114.             ant = aux;
  115.             aux = aux->Seguinte;
  116.         }
  117.     }
  118.  
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement