JehQueiroz
(usa Linux Mint)
Enviado em 01/02/2015 - 11:16h
#include<stdio.h>
#include <time.h>
void Quick(int vetor[201], int inicio, int fim);
int main()
{
clock_t time1, time2, time_diff;
time1 = clock()/(CLOCKS_PER_SEC/1000);
int i;
int vetor[201] = {597, 152, 343, 164, 3, 699, 307, 687, 710, 308, 500, 262, 724, 277, 702, 548, 377, 753, 66, 894, 600, 326, 851, 735, 113, 755, 460, 942, 614, 931, 56, 562, 82, 751, 77, 437, 801, 384, 475, 862, 43, 974, 124, 766, 602, 177, 665, 978, 929, 83, 223, 880, 408, 425, 614, 872, 180, 425, 813, 793, 355, 221, 706, 789, 323, 783, 225, 123, 166, 699, 984, 208, 24, 459, 325, 626, 635, 990, 955, 915, 72, 178, 147, 479, 602, 112, 351, 133, 537, 515, 277, 243, 87, 983, 383, 409, 765, 959, 531, 282, 657, 867, 489, 33, 325, 165, 658, 312, 154, 964, 578, 577, 141, 724, 56, 95, 836, 758, 227, 724, 624, 856, 318, 711, 838, 53, 119, 954, 11, 2, 235, 20, 868, 75, 52, 192, 239, 61, 855, 745, 24, 433, 321, 165, 508, 728, 611, 343, 837, 837, 418, 461, 44, 88, 171, 881, 140, 641, 186, 502, 994, 772, 521, 861, 846, 572, 405, 85, 632, 611, 181, 8, 43, 501, 172, 551, 229, 782, 245, 65, 970, 15, 877, 14, 102, 399, 246, 593, 392, 784, 94, 385, 555, 967, 598, 401, 538, 354, 837, 522};
printf("Vetor desordenado:\n");
for(i = 0; i < 201; i++)
{
printf("%d ", vetor[i]);
}
printf("\n");
Quick(vetor, 0, 200);
printf("Vetor ordenado:\n");
for(i = 0; i < 201; i++)
{
printf("%d ", vetor[i]);
}
printf("\n");
time2 = clock()/(CLOCKS_PER_SEC/1000);
time_diff = time2 - time1;
printf("\n %d milisegundos\n", time_diff);
system("PAUSE");
}
void Quick(int vetor[201], int inicio, int fim)
{
int pivo, aux, i, j, meio;
i = inicio;
j = fim;
meio = (int) ((i + j) / 2);
pivo = vetor[meio];
do
{
while (vetor[i] > pivo && i<j) i++;
while (pivo> vetor[j] && j>i) j--;
if(i <= j)
{
aux = vetor[i];
vetor[i] = vetor[j];
vetor[j] = aux;
i = i + 1;
j = j - 1;
}
}while(i<=j);
if(inicio < j) Quick(vetor, inicio, j);
if(i < fim) Quick(vetor, i, fim);
}