/*** * PArte un vector en dos trozos seg�n el valor pasado a partition * Find().addItem(int)*.partition(int) * Nos sobran los mutatnes que no afecten a esas 3 operaciones de arriba */ package paper; import java.util.Vector; public class Find { int[] A; int nElems; int mF; public Find(int size) { A=new int[size]; nElems=0; } public void addItem(int v) { A[nElems++]=v; } public void partition(int f) { mF=f; int numPosicionesMayores=0, numPosicionesMenores=0; for (int i=0; i<A.length; i++) { if (A[i]<A[f]) numPosicionesMenores++; else if (A[i]>A[f]) numPosicionesMayores++; } int[] posicionesMenores=new int[numPosicionesMenores]; int[] posicionesMayores=new int[numPosicionesMayores]; int[] posicionesIguales=new int[A.length-numPosicionesMenores-numPosicionesMayores]; int contPosMenores=0, contPosMayores=0, contPosIguales=0; for (int i=0; i<A.length; i++) { if (A[i]<A[f]) posicionesMenores[contPosMenores++]=i; else if (A[i]>A[f]) posicionesMayores[contPosMayores++]=i; else posicionesIguales[contPosIguales++]=i; } int[] aux=new int[A.length]; int cont=0; for (int i=0; i<posicionesMenores.length; i++) { aux[cont++]=A[posicionesMenores[i]]; } for (int i=0; i<posicionesIguales.length; i++) { aux[cont++]=A[posicionesIguales[i]]; } for (int i=0; i<posicionesMayores.length; i++) { aux[cont++]=A[posicionesMayores[i]]; } this.A=aux; } /*public boolean isCorrect() { int midValue=A[mF]; for (int i=0; i<mF; i++) if (A[i]>midValue) return false; for (int i=mF+1; i<A.length; i++) if (A[i]<midValue) return false; return true; } public Find reference() { return this; } public String toString() { String result=""; for (int i=0; i<A.length; i++) result+=A[i]+","; return result; } public boolean equals(Object o) { if (!(o instanceof Find)) return false; Find auxi=(Find) o; if (auxi.A.length!=A.length) return false; for (int i=0; i<A.length; i++) if (auxi.A[i]!=A[i]) return false; return true; }*/ public int [] getVector(){ return A; } }