Delete kinda works

This commit is contained in:
Matti 2024-05-06 17:46:02 +02:00
parent ff28fcb099
commit be8b24140e
2 changed files with 27 additions and 1 deletions

View File

@ -8,6 +8,18 @@ package part1.aufg6;
*/
public class Anwendung {
public static void main(String[] args){
System.out.println("Moin");
LinkedList myList = new LinkedList();
myList.add(5);
myList.add("e");
myList.add(3.1415);
myList.add(1);
myList.add(1);
myList.add(1);
myList.add(2);
myList.add(3);
myList.delete(1);
myList.printALL();
}
}

View File

@ -62,4 +62,18 @@ public class LinkedList<T>{
next = next.next; // must happen at end of loop
}
}
public void delete(T value){
if (anchor.data == value){
anchor = anchor.next;
}
var next = anchor.next;
while (next != null){
if (next.next.data == value){
next.next = next.next.next;
return;
}
next = next.next;
}
}
}