Code to get the biggest number buggy?

0

I created the code that is in the image to go through a double-chained list and get the largest token, and I sent the following entry (add at the end): 12, 17, 14, 23, 8, 10. It should be removed 23 and when I call again the method would remove 17, but removing 10 and 23. What is wrong? Eh bug? or my mistake?

publicclassListaNOrdenada{privateNoinicio;privateinttam;privateNofim;publicvoidadd(Integernum){Non=newNo();n.setToken(num);if(tam==0){inicio=n;fim=n;}else{fim.setProx(n);n.setAnt(fim);fim=n;}tam++;}publicNoremover(){Noaux=inicio;Nomaior=inicio;inti=0;while(aux.getProx()!=null){if(aux.getToken()<aux.getProx().getToken()){maior=aux.getProx();System.out.println("maior: " +maior.getToken());
            }
            aux = aux.getProx();
            i++;
        }
        System.out.println("maior: " +maior.getToken());
        if(maior == inicio) {
            inicio = inicio.getProx();
            inicio.setAnt(null);
        }else if(maior == fim) {
            fim = fim.getAnt();
            fim.setProx(null);
        }else{
            maior.getAnt().setProx(maior.getProx());
            maior.getProx().setAnt(maior.getAnt());
        }
        tam--;
        return maior;

    }

    public void imprimir() {
        No aux = inicio;
        System.out.println(aux.getToken());
        while(aux.getProx() != null) {
            aux = aux.getProx();
            System.out.println(aux.getToken());
        }
    }
}
'
    
asked by anonymous 20.05.2017 / 00:52

0 answers