Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  teste
Language: C/C++
Code:
#include<stdlib.h>
#include<stdio.h>
#include<time.h>
unsigned long long vo[10000000];
unsigned long long vd[10000000];
unsigned long long vi[10000000];
void enchevetor()
{
     srand (time(NULL));
     unsigned long long i;
     for(i=0;i<10000000;i++)
     {
          vo[i]=i+1;
          vd[i]= rand() % 10000000;
          vi[i]=10000000-i;
     }     
}
unsigned long long bubbleSort(unsigned long long vetor[], unsigned long long tamanho)
{
     unsigned long long limite, i, j, t, troca=0, comparacoes=0;
     for(i=0;i<tamanho;i++)
     //printf("%llu\n",vetor[i]);
    for (i = 0; i < tamanho; i++) {
        limite = (tamanho - 1) - i;
        for (j = 0; j < limite; j++) {
            comparacoes++;
            if (vetor[j] > vetor[j + 1]) {
                troca++;
                t = vetor[j];
                vetor[j] = vetor[j + 1];
                vetor[j + 1] = t;
            }
        }
    }
    
    
     
     printf("%llu : %llu \n",comparacoes, troca);
     
     
}

unsigned long long escolha(unsigned long long tam)
{
     unsigned long long i;
     printf("\nVO %llu\n", tam);
     for(i=0;i<1;i++)
     bubbleSort(vo, tam);
     printf("\nVI %llu\n", tam);
     for(i=0;i<1;i++)
     bubbleSort(vi, tam);
}

int main()
{
     float tempo;
     time_t t_ini, t_fim;
     int i;
     enchevetor();
     escolha(10);
     escolha(100);
     escolha(1000);
     escolha(10000);
     escolha(100000);
     escolha(1000000);
     escolha(10000000);
     
     
     //bubbleSort(vd,100);
     
     
}
Comments: