class no {
public int dado;
public no prox;
}
class lista {
no ini = null;
no fim = null;
public void inserir(int num) {
no novo = new no();
novo.dado = num;
novo.prox = null;
if (ini == null) {
ini = novo;
} else {
fim.prox = novo;
}
fim = novo;
}
public void imp() {
no x = ini;
while (x != null) {
x = x.prox;
}
}
public void remover(int num){
no ant = null;
no atual = ini;
while (atual != null) {
if (atual.dado == num) {
ant.prox = atual.prox;
}
ant = atual;
atual = atual.prox;
}
}
}
class Teste {
public static void main
(String[] args
) { lista lst = new lista();
lst.remover(8);
lst.inserir(15);
lst.inserir(8);
lst.imp();
lst.remover(8);
lst.imp();
}
}
Y2xhc3Mgbm8gewoJcHVibGljIGludCBkYWRvOwoJcHVibGljIG5vIHByb3g7Cn0KCmNsYXNzIGxpc3RhIHsKCW5vIGluaSA9IG51bGw7CglubyBmaW0gPSBudWxsOwoJCglwdWJsaWMgdm9pZCBpbnNlcmlyKGludCBudW0pIHsKCSAgICBubyBub3ZvID0gbmV3IG5vKCk7CgkgICAgbm92by5kYWRvID0gbnVtOwoJICAgIG5vdm8ucHJveCA9IG51bGw7CgkgICAgaWYgKGluaSA9PSBudWxsKSB7CgkgICAgICAgIGluaSA9IG5vdm87CgkgICAgfSBlbHNlIHsKCSAgICAgICAgZmltLnByb3ggPSBub3ZvOwoJICAgIH0KCSAgICBmaW0gPSBub3ZvOwoJfQoJCglwdWJsaWMgdm9pZCBpbXAoKSB7CgkgICAgbm8geCA9IGluaTsKCSAgICB3aGlsZSAoeCAhPSBudWxsKSB7CgkgICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbih4LmRhZG8pOwoJICAgICAgICB4ID0geC5wcm94OwoJICAgIH0KCX0KCQoJcHVibGljIHZvaWQgcmVtb3ZlcihpbnQgbnVtKXsKCQlubyBhbnQgPSBudWxsOwoJCW5vIGF0dWFsID0gaW5pOwoJCXdoaWxlIChhdHVhbCAhPSBudWxsKSB7CgkJCWlmIChhdHVhbC5kYWRvID09IG51bSkgewoJCQkJYW50LnByb3ggPSB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