This commit is contained in:
La Programmatrice Verde
2026-03-24 08:48:06 +01:00
parent f35818db88
commit 1e4c8f2a5f
2 changed files with 28 additions and 2 deletions

View File

@@ -13,6 +13,16 @@ public class Lista<E> {
return this.size; return this.size;
} }
public void addFirst(E info) {
if (this.testa == null) {
this.testa = new Nodo<>(info);
}
else {
Nodo<E> nuovaTesta = new Nodo<>(info);
nuovaTesta.setNext(this.testa);
this.testa = nuovaTesta;
}
}
//addFirst(tipoInfo info): aggiunge un nodo in testa (es. tipoInfo = char, tipoInfo = int) //addFirst(tipoInfo info): aggiunge un nodo in testa (es. tipoInfo = char, tipoInfo = int)
//addLast(tipoInfo info): aggiunge un nodo in coda (es. tipoInfo = char, tipoInfo = int) //addLast(tipoInfo info): aggiunge un nodo in coda (es. tipoInfo = char, tipoInfo = int)

View File

@@ -1,11 +1,27 @@
package linkedlist; package linkedlist;
public class Nodo<E> { public class Nodo<E> {
Nodo next; private Nodo<E> next;
E info; private E info;
public Nodo(E info) { public Nodo(E info) {
this.info = info; this.info = info;
this.next = null; this.next = null;
} }
public Nodo<E> getNext() {
return next;
}
public void setNext(Nodo<E> next) {
this.next = next;
}
public E getInfo() {
return info;
}
public void setInfo(E info) {
this.info = info;
}
} }