Delete works?
This commit is contained in:
parent
ac503234b2
commit
7d1af4bd85
@ -14,10 +14,13 @@ public class Anwendung {
|
||||
myList.add("b");
|
||||
myList.add("c");
|
||||
myList.add("d");
|
||||
myList.add("e");
|
||||
myList.add("f");
|
||||
// myList.add("e");
|
||||
// myList.add("f");
|
||||
|
||||
myList.delete("e");
|
||||
myList.delete("a");
|
||||
myList.delete("b");
|
||||
myList.delete("c");
|
||||
myList.delete("d");
|
||||
myList.printALL();
|
||||
}
|
||||
}
|
||||
|
@ -33,6 +33,9 @@ public class LinkedList<T>{
|
||||
|
||||
}
|
||||
public void printALL(){ // correct???
|
||||
if (anchor==null){
|
||||
return;
|
||||
}
|
||||
Cell<T> next = anchor.next;
|
||||
|
||||
System.out.println(anchor.data);
|
||||
@ -64,22 +67,32 @@ public class LinkedList<T>{
|
||||
}
|
||||
|
||||
public void delete(T value){
|
||||
System.out.println("Removing " + '"' + value + '"');
|
||||
if (anchor == null)return;
|
||||
if (anchor.data == value){
|
||||
anchor = anchor.next;
|
||||
return;
|
||||
}
|
||||
|
||||
if ((anchor.next != null) && (anchor.next.data == value)){
|
||||
anchor.next = anchor.next.next;
|
||||
}
|
||||
|
||||
var cell = anchor.next;
|
||||
|
||||
while (cell != null){
|
||||
|
||||
if (cell.next != null) {
|
||||
while (cell != null && cell.next != null){
|
||||
if (cell.next.data == value) {
|
||||
if (cell.next.next != null) {
|
||||
cell.next = cell.next.next;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
cell = cell.next;
|
||||
if ((cell.next.next == null) && (cell.next.data == value)){
|
||||
cell.next = null;
|
||||
return;
|
||||
}
|
||||
|
||||
cell = cell.next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user