From f018d72b9c7fc4e50c2327667ce073adaae80da1 Mon Sep 17 00:00:00 2001 From: La Programmatrice Verde Date: Tue, 24 Mar 2026 08:51:58 +0100 Subject: [PATCH] addLast --- src/linkedlist/Lista.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/linkedlist/Lista.java b/src/linkedlist/Lista.java index 6d6fe38..39b3471 100644 --- a/src/linkedlist/Lista.java +++ b/src/linkedlist/Lista.java @@ -24,7 +24,21 @@ public class Lista { } } -//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 nuovaCoda = new Nodo<>(info); + + Nodo 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