addLast
This commit is contained in:
@@ -24,7 +24,21 @@ public class Lista<E> {
|
||||
}
|
||||
}
|
||||
|
||||
//addFirst(tipoInfo info): aggiunge un nodo in testa (es. tipoInfo = char, tipoInfo = int)
|
||||
public void addLast(E info) {
|
||||
if (this.testa == null) {
|
||||
addFirst(info);
|
||||
}
|
||||
else {
|
||||
Nodo<E> nuovaCoda = new Nodo<>(info);
|
||||
|
||||
Nodo<E> coda = this.testa;
|
||||
while (coda.getNext() != null) {
|
||||
coda = coda.getNext();
|
||||
}
|
||||
coda.setNext(nuovaCoda);
|
||||
}
|
||||
}
|
||||
|
||||
//addLast(tipoInfo info): aggiunge un nodo in coda (es. tipoInfo = char, tipoInfo = int)
|
||||
//addElementAt(tipoInfo info, int pos): aggiunge un nodo nella posizione indicata da pos
|
||||
//removeFirst(): rimuove il nodo in testa
|
||||
|
||||
Reference in New Issue
Block a user