public void insereInicio(int data) { NohLista noh = new NohLista(data); if (isEmpty()) { inicio = fim = noh; } else { inicio.setPrevio(noh); noh.setNext(inicio); inicio = noh; } }
public void insereFim(int data) { NohLista noh = new NohLista(data); if (isEmpty()) { inicio = fim = noh; } else { fim.setNext(noh); noh.setPrevio(fim); fim = noh; } }
public void remove(int noh) { bool achou = false; if (isEmpty()) { throw new Exception(); } for (NohLista aux = inicio; aux != null; aux = aux.getNext()) { if (aux.getData() == noh) { if (aux == inicio) { inicio = inicio.getNext(); inicio.setPrevio(null); } else if (aux == fim) { fim = fim.getPrevio(); fim.setNext(null); } else { aux.getPrevio().setNext(aux.getNext()); aux.getNext().setPrevio(aux.getPrevio()); } achou = true; break; } } if (!achou) { Console.Error.WriteLine("Item não encontrado"); throw new Exception(); } }