I am having a cruel difficulty with regard to a java method. To delimit the position of the node, I only have the getProximo () method as follows, so I can not delete the node passed as a parameter, not excluding all consecutive ones.
package br.edu.unifil.comp2022.listadinamica;
/**
* Write a description of class ListaDinamica here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class ListaDinamica{
private Node inicio;
private Node aux;
private int _tamanho = 0;
public ListaDinamica(){
}
public void inserir(Node node){
if(inicio == null){
inicio = node;
}else{
Node aux = inicio;
while(aux.getProximo() != null){
aux = aux.getProximo();
}
aux.setProximo(node);
}
aux = inicio;
}
public void remover(Node node){
if(aux != node){
while(aux.getProximo() != null && aux.getProximo() != node){
aux = aux.getProximo();
}
}else{
aux = null;
}
aux = inicio;
}
public boolean existe(Node node){
if(aux == null){
return false;
}else if(aux == node){
return true;
}else if(aux.getProximo() != null){
aux = aux.getProximo();
return existe(aux);
}
aux = inicio;
return false;
}
public int tamanho(){
Node aux = inicio;
while(aux != null){
aux = aux.getProximo();
_tamanho++;
}
return _tamanho;
}
@Override
public String toString(){
String ret;
if(inicio == null){
ret = "[]";
}else{
ret = "[";
Node aux = inicio;
while(aux.getProximo() != null){
ret = ret + aux + ", ";
aux = aux.getProximo();
}
}
ret = ret + "]";
return ret;
}
}