#include #include #include int verificaVetor(int vetor[], int n){ if(n-1 == 0){ return 1; } if((n-1)%2 == 0){ if(vetor[n-1] > vetor[((n-1)/2)-1]){ return 0;} else { verificaVetor(vetor,n-1); } } else { if(vetor[n-1] > vetor[(n-1)/2]) { return 0;} else { verificaVetor(vetor,n-1);} } } void heapMax(int *vetor[], int n, int y){ int a = y; if(n-1 == 0){ if(verificaVetor(vetor,y) == 0){ heapMax(vetor,a,y); } } else { int i; for(i=0;i vetor[((n-1)/2)]){trocaValores(vetor,(n-1),((n-1)/2)); heapMax(vetor,n-1,y);} else{ heapMax(vetor,n-1,y); } } } else{ if(vetor[n-1] > vetor[n-2]){ if(vetor[n-1]> vetor[(((n-1)/2)-1)]){ trocaValores(vetor,(n-1),(((n-1)/2)-1)); heapMax(vetor,n-2,y); } else{ heapMax(vetor,n-2,y); } } else{ if(vetor[n-2]>vetor[(((n-1)/2)-1)]) { trocaValores(vetor,(n-2),(((n-1)/2)-1)); heapMax(vetor,n-2,y); } else{ heapMax(vetor,n-2,y); } } } } void trocaValores( int *vetor[],int a, int b){ int aux; aux = vetor[a]; vetor[a] = vetor[b]; vetor[b] = aux; } int main() { int vetor[] = {5,12,64,1,37,90,91,97}; heapMax(&vetor,8,8); int i; for( i =0; i<8;i++){ printf("%d\n",&vetor[i]); } return 0; }