Created
June 7, 2012 21:24
-
-
Save delucas/2891621 to your computer and use it in GitHub Desktop.
#untref #lp1 - ArregloOrdenable, que contabiliza las operaciones para analizar costos
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
public class ArregloOrdenable { | |
public static final int COSTO_ELEMENTO = 5; | |
public static final int COSTO_INTERCAMBIO = 10; | |
public static final int COSTO_LARGO = 15; | |
private int[] arreglo; | |
private int peticionesElemento; | |
private int peticionesIntercambio; | |
private int peticionesLargo; | |
public ArregloOrdenable(int[] arreglo) { | |
this.arreglo = arreglo; | |
} | |
public int getLargo() { | |
this.peticionesLargo++; | |
return this.arreglo.length; | |
} | |
public int get(int posicion) { | |
this.peticionesElemento++; | |
return this.arreglo[posicion]; | |
} | |
public void intercambiar(int posicionUno, int posicionDos) { | |
int aux = this.arreglo[posicionUno]; | |
this.arreglo[posicionUno] = this.arreglo[posicionDos]; | |
this.arreglo[posicionDos] = aux; | |
this.peticionesIntercambio++; | |
} | |
public int getCostoActual() { | |
return this.peticionesElemento * COSTO_ELEMENTO + | |
this.peticionesIntercambio * COSTO_INTERCAMBIO + | |
this.peticionesLargo * COSTO_LARGO; | |
} | |
public int getPeticionesElemento() { | |
return peticionesElemento; | |
} | |
public int getPeticionesIntercambio() { | |
return peticionesIntercambio; | |
} | |
public int getPeticionesLargo() { | |
return peticionesLargo; | |
} | |
public boolean estaOrdenado() { | |
for (int i = 0; i < this.arreglo.length - 1; i++) { | |
if (this.arreglo[i] > this.arreglo[i+1]) { | |
return false; | |
} | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment