Java
/** * * @authores Luiz.Lima ,Stephan Renato */ class Ordenado { int maior; Canvas cn; void anima(Canvas canvas,int m){ cn = canvas; maior = m; } int [] bubblesort (int[] array, boolean animacao){
boolean troca = true; int comp = 0; int troc = 0; if (animacao && array.length array[i+1]){ cn.eraseLine(50+((700*i)/array.length), 550, 50+((700*i)/array.length), 550 -((500*array[i])/maior)); int aux = array[i+1]; array[i+1] = array[i]; array[i] = aux; troca = true; //cn.wait(1); troc++; cn.setForegroundColour(Color.RED); cn.drawLine(50+((700*i)/array.length), 550, 50+((700*i)/array.length), 50); cn.wait(2); cn.eraseLine(50+((700*i)/array.length), 550, 50+((700*i)/array.length), 50); cn.setForegroundColour(Color.black); //cn.drawLine(50+((700*i)/array.length), 550, 50+((700*i)/array.length), 550 -((500*array[i])/maior));
} cn.setForegroundColour(Color.RED); cn.drawString("Comparaçõs: " + Integer.toString(comp), 10, 20); cn.drawString("Trocas: " + Integer.toString(troc), 10, 45); cn.wait(3); cn.drawLine(50+((700*i)/array.length), 550, 50+((700*i)/array.length), 550 -((500*array[i])/maior));
} } }else{ while (troca == true) { troca = false; for (int i = 0; i < (array.length)-1; i++){