Ola galera , estou fazendo um trabalho sobre técnicas de ordenações, e o prof passou um modelo a ser seguido para a entrega, porém eu não entendi nada dele se vcs poderem me dar uma luz!
Se poderem dar só uma comentada no código já ajuda muito,eu não consegui ver onde ele atribui o valor do vetor , a parte da implementação da logica da ordenação foi eu que fiz.
public class Bolha {
public enum Ordem {CRESCENTE, DECRESCENTE};
public Ordem ordem = Ordem.CRESCENTE; // valor padrão
private int[] valores;
private int trocas = 0;
private int comparacoes = 0;
private boolean ordenado;
private boolean gerarEstatistica;
public boolean isGerarEstatistica() {
return gerarEstatistica;
}
public void setGerarEstatistica(boolean gerarEstatistica) {
this.gerarEstatistica = gerarEstatistica;
}
public int[] getValores() {
return valores;
}
public void setValores(int[] valores) {
this.valores = valores;
}
public Ordem getOrdem() {
return ordem;
}
public int getTrocas() {
return trocas;
}
public int getComparacoes() {
return comparacoes;
}
public Bolha() {
}
public Bolha(int[] valores) {
this.valores = valores;
}
public Bolha(int[] valores, Ordem ordem) {
this.valores = valores;
this.ordem = ordem;
}
public void ordenar(){
//--se já estiver ordenado não executa novamente o processo --
if (ordenado){
return;
}
switch(ordem){
case CRESCENTE :
if (isGerarEstatistica()){
ordenarCrescenteContab();
}
else{
ordenarCrescente();
}
break;
case DECRESCENTE:
if (isGerarEstatistica()){
ordenarDecrescenteContab();
}
else{
ordenarDecrescente();
}
break;
};
}
public void ordenarCrescente(){
int aux = 0;
for (int i = 0 ;i < valores.length - 1;i++){
boolean extroca = false;
for (int j = 0 ;j < ( ( valores.length - 1 ) - i );j++){
if ( valores[j] > valores[j + 1] ){
aux = valores[j];
valores[j] = valores[j + 1];
valores[j + 1] = aux;
extroca = true;
}
}
if(!extroca){
break;
}
}
System.out.println("ordenarCrescente");
for(int l : valores){
System.out.print(valores+" ,");
}
}
public void ordenarCrescenteContab(){
System.out.println("ordenarCrescenteContab");
}
public void ordenarDecrescente(){
System.out.println("ordenarDecrescente");
}
public void ordenarDecrescenteContab(){
System.out.println("ordenarDecrescenteContab");
}
}
metodo principal
public class TesteBolha {
public static void main(String[] args) {
int [] vet = {9,8,7,6,5,4,3,2,1};
Bolha bolha = new Bolha(vet, Bolha.Ordem.CRESCENTE);
bolha.setGerarEstatistica(Boolean.FALSE);
bolha.ordenar();
bolha.setGerarEstatistica(Boolean.TRUE);
bolha.ordenar();
bolha = new Bolha(vet, Bolha.Ordem.DECRESCENTE);
bolha.setGerarEstatistica(Boolean.FALSE);
bolha.ordenar();
bolha.setGerarEstatistica(Boolean.TRUE);
bolha.ordenar();
}
}