class Lista {
private static class Nodo<T> { // static private
private T info;
// Object info; // package access
Nodo<T> next;
Nodo(T info, Nodo<T> next) {
this.info = info;
this.next = next;
System.out.println(this.info+" "+this.next);
}
}
private int count = 0;
private Nodo<T> testa = null;
public int getCount() {
return count;
}
/**
* Metodo che inserisce un elemento nella lista
*
*/
public <T>void add(T x) {
testa = new Nodo(x, testa);
++count;
}
/**
* Metodo trova un elemento nella lista
*
*/
public <T>T find (T x){
Nodo tmp = testa;
while (tmp != null) {
x = tmp.info;
if (b.nome.equals(x))
return T;
tmp = tmp.next;
}
return null;
}
/**
* Metodo che cancella un elemento qualsiasi dalla lista
* @exception ListaVuotaException
*/
public <E>boolean cancella(Object a) throws ListaVuotaException{
Nodo oldTemp;
Nodo temp=testa;
if(testa==null)
return false;
if(a==(Animale)testa.info)
testa=testa.next;
else
{
while(temp!=null){
oldTemp=temp;
temp=temp.next;
if(a==(Animale)temp.info){
oldTemp.next=temp.next;
break;
}
}
}
return true;
}
}