addFirst
This commit is contained in:
@@ -13,6 +13,16 @@ public class Lista<E> {
|
||||
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)
|
||||
//addLast(tipoInfo info): aggiunge un nodo in coda (es. tipoInfo = char, tipoInfo = int)
|
||||
|
||||
@@ -1,11 +1,27 @@
|
||||
package linkedlist;
|
||||
|
||||
public class Nodo<E> {
|
||||
Nodo next;
|
||||
E info;
|
||||
private Nodo<E> next;
|
||||
private E info;
|
||||
|
||||
public Nodo(E info) {
|
||||
this.info = info;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user