Ir ao conteúdo
  • Cadastre-se

AMS13

Membro Júnior
  • Posts

    1
  • Cadastrado em

  • Última visita

Reputação

0
  1. Esse é o programa inicial, desde já agradeço pela ateção. #include <stdio.h> #include <stdlib.h> #include <time.h> #define TAM_VETOR 10 void merge(int vetor[], int tamanho) { int meio = tamanho / 2; int i = 0, j = meio, k = 0; int aux[tamanho]; while( i < meio && j < tamanho ){ if( vetor <= vetor[j] ) aux[k] = vetor[i++]; else aux[k] = vetor[j++]; k++; } if( i == meio ) while( j < tamanho ) aux[k++] = vetor[j++]; else while( i < meio ) aux[k++] = vetor[i++]; for( i = 0; i < tamanho; i++ ) vetor = aux; } int mergeSort(int vetor[], int tamanho){ int meio = tamanho / 2; if( tamanho > 1 ){ mergeSort(vetor, meio); mergeSort(vetor + meio, tamanho - meio); merge(vetor, tamanho); } } int main(){ int vetor[TAM_VETOR]; // Preenche o vetor com valores aleatórios 0-100 srand(time(NULL)); for(int i = 0; i < TAM_VETOR; i++){ vetor = rand()%100; printf("%d, ", vetor); } printf("\n\n"); mergeSort(vetor, TAM_VETOR); for(int i = 0; i < TAM_VETOR; i++){ printf("%d, ", vetor); } return 0; }

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...

 

GRÁTIS: ebook Redes Wi-Fi – 2ª Edição

EBOOK GRÁTIS!

CLIQUE AQUI E BAIXE AGORA MESMO!