Compare commits
3 Commits
ff28fcb099
...
7d1af4bd85
Author | SHA1 | Date | |
---|---|---|---|
|
7d1af4bd85 | ||
|
ac503234b2 | ||
|
be8b24140e |
@ -8,6 +8,19 @@ package part1.aufg6;
|
||||
*/
|
||||
public class Anwendung {
|
||||
public static void main(String[] args){
|
||||
System.out.println("Moin");
|
||||
LinkedList myList = new LinkedList();
|
||||
|
||||
myList.add("a");
|
||||
myList.add("b");
|
||||
myList.add("c");
|
||||
myList.add("d");
|
||||
// myList.add("e");
|
||||
// myList.add("f");
|
||||
|
||||
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);
|
||||
@ -62,4 +65,34 @@ public class LinkedList<T>{
|
||||
next = next.next; // must happen at end of loop
|
||||
}
|
||||
}
|
||||
|
||||
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 && cell.next != null){
|
||||
if (cell.next.data == value) {
|
||||
if (cell.next.next != null) {
|
||||
cell.next = cell.next.next;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if ((cell.next.next == null) && (cell.next.data == value)){
|
||||
cell.next = null;
|
||||
return;
|
||||
}
|
||||
|
||||
cell = cell.next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user