impl: cll to array list
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package appointmentplanner.customlist;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
@@ -122,6 +123,7 @@ public class CustomLinkedListImpl<T> implements CustomLinkedList<T> {
|
||||
}
|
||||
|
||||
CustomLinkedListNode<T> nodeBefore = traverseFind(head, reference, ItemPosition.BEFORE);
|
||||
|
||||
CustomLinkedListNode<T> nodeToInsert = new CustomLinkedListNode<>(nodeBefore.getNext(), item);
|
||||
nodeBefore.setNext(nodeToInsert);
|
||||
}
|
||||
@@ -204,4 +206,18 @@ public class CustomLinkedListImpl<T> implements CustomLinkedList<T> {
|
||||
return items;
|
||||
}
|
||||
|
||||
private ArrayList<T> mapToArrayList(CustomLinkedListNode<T> node, ArrayList<T> list) {
|
||||
if (node == null) {
|
||||
return list;
|
||||
}
|
||||
mapToArrayList(node.getNext(), list);
|
||||
list.add(node.getItem());
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList<T> toArrayList() {
|
||||
return mapToArrayList(head, new ArrayList<>());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user