Delete kinda works
This commit is contained in:
parent
ff28fcb099
commit
be8b24140e
@ -8,6 +8,18 @@ package part1.aufg6;
|
|||||||
*/
|
*/
|
||||||
public class Anwendung {
|
public class Anwendung {
|
||||||
public static void main(String[] args){
|
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,4 +62,18 @@ public class LinkedList<T>{
|
|||||||
next = next.next; // must happen at end of loop
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user