numero de comparaciones y numero de iteraciones
Publicado por Alex (2 intervenciones) el 09/06/2016 02:10:53
Me podrian decir si estoy bien necesito que mi algoritmo muestre el numero de comparaciones y el numero de iteraciones
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
public void ShellSort(int num_v, Vehiculo[] arreglo, Comparator compara) {
TInicio = System.currentTimeMillis();
Vehiculo aux;
for (int gap = num_v / 2; gap > 0; gap = gap == 2 ? 1 : (int) (gap / 2.2)) {
for (int i = gap; i < num_v; i++) {
aux = arreglo[i];
int j;
for (j = i; j >= gap && compara.compare(aux, arreglo[j - gap]) < 0; j -= gap) {
arreglo[j] = arreglo[j - gap];
contador3++;
}
arreglo[j] = aux;
}
iterador3++;
}
System.out.println(" ***** Lista de vehiculos ordenados \"Shell Sort\" *****");
System.out.print("\nVehiculo\tPlaca\t\tMarca\t\tAño\t\tFecha Fab\t\tPrecio\n");
for (int i = 0; i < num_v; i++) {
System.out.println("" + (i + 1) + arreglo[i]);
}
System.out.println("el numero de comparaciones :"+contador3);
System.out.println("el numero de iteraciones :"+iterador3);
TFin = System.currentTimeMillis();
tiempo4 = TFin - TInicio;
System.out.println("Tiempo de ejecución en milisegundos: " + tiempo4);
}
Valora esta pregunta


0