Está en la página 1de 8

Código del programa

#include<stdio.h>

#include<stdlib.h>

#include<cmath>

#include<vector>

#include<time.h>

#include<iostream>

#include<ctime>

unsigned t0, t1;

using namespace std;

void Radix(int a[] , int n);

vector< vector <int> > Vec;

//-----------------------------------------------------metodo Quicksort

int colocar(int *v, int b, int t){

int i;

int pivote, valor_pivote;

int temp;

pivote = b;

valor_pivote = v[pivote];

for (i=b+1; i<=t; i++){

if (v[i] < valor_pivote){

pivote++;

temp=v[i];

v[i]=v[pivote];

v[pivote]=temp;

temp=v[b];

v[b]=v[pivote];

v[pivote]=temp;

return pivote;
}

//---------------------------------------------------metodo quicksort

void Quicksort(int* v, int b, int t){

int pivote;

if(b < t){

pivote=colocar(v, b, t);

Quicksort(v, b, pivote-1);

Quicksort(v, pivote+1, t);

//----------------------------------------------------metodo shellsort

void Shellsort(int* V, int n){

int i,j,inc,temp;

for(inc=1;inc<n;inc=inc*3-1);

while(inc > 0){

for(i=inc; i < n ; i++){

j=i;

temp= V[i];

while((j >= inc) && (V[j-inc]>temp))

V[j]= V[j-inc];

j=j- inc;

V[j]= temp;

inc/=2;

//------------------------------------------------------metodo radix

void Radix(int a[] , int n){


Vec.resize(10);

int temp , m=0;

for(int i=0;i<7;i++){

for(int j=0;j<n;j++){

temp= (int)(a[j]/pow(10,i))%10;

Vec[temp].push_back(a[j]);

for(int k=0;k<10;k++)

for(int l=0;l<Vec[k].size();l++){

a[m]=Vec[k][l];

m++;

Vec[k].clear();

m=0;

//-------------------------------------------------------metodo burbuja

int burbuja( int* V,int n ){

int i,j ,aux;

for (i=0;i<=n-1;i++){

for(j=i;j<n;j++){

if(V[i]>V[j]){

aux = V[i];

V[i]=V[j];

V[j]=aux;

}
}

//------------------------------------------------------------------metodo main

main()

{ FILE *archivo;

int numero, n,i;

srand (time(NULL));

cout << "Cuantos numeros desea generar?: ";

cin >> n;

archivo=fopen("datos4.dat","w");

for(int i=1; i<n ; i++){

numero =rand() % 10000 + 1; ;

fprintf(archivo,"%d\n",numero);

if((i%100)==0)

printf("*");

numero =rand() % 10000 + 1; ;

fprintf(archivo,"%d",numero);

cout << "\n\n Se han generado " << n << " numeros";

//burbuja

int V[n];

archivo=fopen("datos4.dat","r");

while(!feof(archivo))

fscanf(archivo, "%d" ,&V[i]);

i++;

}
t0=clock();

burbuja( V,n);

t1=clock();

double time = (double(t1-t0)/CLOCKS_PER_SEC);

time=time*1000;

cout<< " \n ordenamiento por burbuja ";

cout<< "\ntiempo de ejecucion \n "<< time <<" milisegundo "<<endl;

//radix

archivo=fopen("datos4.dat","r");

i=0;

while(!feof(archivo))

fscanf(archivo, "%d",&V[i]);

i++;

t0=clock();

Radix( V,n);

t1=clock();

time=time*1000;

cout<< " \n ordenamiento por Radix ";

cout<< "\ntiempo de ejecucion \n "<< time <<" milisegundo "<<endl;

//shellsort

archivo=fopen("datos4.dat","r");

i=0;

while(!feof(archivo))

fscanf(archivo, "%d",&V[i]);

i++;
}

t0=clock();

Shellsort( V,n);

t1=clock();

time=time*1000;

cout<< " \n ordenamiento por Shellsort ";

cout<< "\ntiempo de ejecucion \n "<< time <<" milisegundo "<<endl;

// quicksort

archivo=fopen("datos4.dat","r");

i=0;

while(!feof(archivo))

fscanf(archivo, "%d",&V[i]);

i++;

t0=clock();

Quicksort( V,0,n-1);

t1=clock();

time=time*1000;

cout<< " \n ordenamiento por Quicksort ";

cout<< "\ntiempo de ejecucion \n "<< time <<" milisegundo "<<endl;

}
CAPTURAS DE EJECUCION

5000

20000

200000

500000
TIEMPOS EN GRAFICAS

5000

5000
150000
100000
50000
0
1 2 3 4

20000

20000
22000
21500
21000
20500
20000
19500
19000
1 2 3 4

200000

100%
200000
80%
60%
40%
20%
0%
1 2 3 4

500000

500000
5000025
5000020
5000015
5000010
5000005
5000000
4999995
4999990
1 2 3 4

También podría gustarte