You are on page 1of 2

static public Vector Vector Vector Vector

int foc=0; static void Mezcla_Directa(int[] recibe, int div){ <Integer> aux1=new Vector(); <Integer> aux2= new Vector(); <Integer> resultante=new Vector(); <Integer> temporal= new Vector();

boolean foco1=true, foco2=false; int particion=div, x=0, y=0; resultante.removeAllElements(); for(int i=0; i<recibe.length;){ if(foco1==true && i<recibe.length ){ for(x=0; x<particion ;x++){ if(i<recibe.length){ aux1.add(recibe[i]); i++; } else break; //c1++; } foco1=false; foco2=true; } if(foco2==true && i<recibe.length){ for(y=0; y<particion; y++){ if(i<recibe.length){ aux2.add(recibe[i]); i++;} else break; //c2++; } foco2=false; foco1=true; } temporal=Intercalacion_simple(aux1,aux2); for(int r=0; r<temporal.size();r++){ resultante.add(temporal.get(r)); } aux1.removeAllElements(); aux2.removeAllElements(); temporal.removeAllElements(); } //for if(analiza(resultante)==1){ for(int p=0; p<resultante.size();p++){ recibe[p]=resultante.get(p); } Mezcla_Directa(recibe,(particion*2)); } else{ foc=1; analiza(resultante); } }

public static int analiza(Vector <Integer> vect){ int foco=0, i=0; while(i<vect.size()){ if(vect.get(i)<vect.get(i+1)){ foco=0; i++; if(i==vect.size()-1){ if(foc==0){ System.out.println("El vector ordenado es: "); for(int l=0; l<vect.size();l++){ System.out.println(vect.get(l) +" "); } } //if foco foco=0; break; }// if termina }//if compara else{ foco=1; break; } } return foco; }

You might also like