Last active
April 6, 2017 07:41
-
-
Save RicardoLara/890da320cbb57dab9d474c9110a1c745 to your computer and use it in GitHub Desktop.
Práctica 3 1/5[AA] - Daniel Cruz García
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
#include "tiempo.h" | |
void quickSort(int A[],int p,int r){ | |
int izq,der,temp,piv; | |
izq = p; | |
der = r; | |
piv = A[(izq+der)/2]; | |
do{ | |
while(A[izq] < piv && izq < r) izq++; | |
while(piv < A[der] && der > p) der--; | |
if(izq <= der){ | |
temp = A[izq]; | |
A[izq] = A[der]; | |
A[der] = temp; | |
izq++; der--; | |
} | |
}while(izq<=der); | |
if(p<der){quickSort(A,p,der);} | |
if(r>izq){quickSort(A,izq,r);} | |
} | |
int main(){ | |
double utime0, stime0, wtime0,utime1, stime1, wtime1; //Variables para medición de tiempos | |
int j,i,n = 0; | |
for(j=0; j<50; j++){ | |
n += 20000; | |
printf("\n------------------- NUMERO %d --------------------- \n",j+1); | |
printf("Ordenando %d datos",n); | |
int k,A[n],s; k=0; | |
FILE *fp = fopen("./DatosAleatorios2.txt","r"); | |
fscanf(fp,"%d",&s); | |
while(k<n){ | |
A[k] = s; | |
fscanf(fp,"%d",&s); k++; | |
} | |
fclose(fp); | |
uswtime(&utime0, &stime0, &wtime0); // Medicion Mode: ON! :v | |
//printf("Arreglo Original: "); | |
//for(i=0; i<n; i++) printf("%d ",A[i]); printf("\n"); printf("\n"); | |
quickSort(A, 0, n-1); | |
//printf("Arreglo Ordenado: "); | |
//for(i=0; i<n; i++) printf("%d ",A[i]); printf("\n"); | |
uswtime(&utime1, &stime1, &wtime1); | |
//Cálculo del tiempo de ejecución del programa | |
printf("\n"); | |
printf("real (Tiempo total) %.10f s\n", wtime1 - wtime0); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment