diff --git a/assignment/src/main/java/appointmentplanner/customlist/CustomLinkedListImpl.java b/assignment/src/main/java/appointmentplanner/customlist/CustomLinkedListImpl.java index ea46089..dc5a189 100644 --- a/assignment/src/main/java/appointmentplanner/customlist/CustomLinkedListImpl.java +++ b/assignment/src/main/java/appointmentplanner/customlist/CustomLinkedListImpl.java @@ -114,20 +114,28 @@ public class CustomLinkedListImpl implements CustomLinkedList { @Override public void insertAfter(T reference, T item) { - // TODO Auto-generated method stub - throw new UnsupportedOperationException("Unimplemented method 'insertAfter'"); + + if (head.getItem().equals(reference)) { + add(item); + return; + } + + CustomLinkedListNode nodeBefore = traverseFind(head, reference, ItemPosition.BEFORE); + CustomLinkedListNode nodeToInsert = new CustomLinkedListNode<>(nodeBefore.getNext(), item); + nodeBefore.setNext(nodeToInsert); } @Override public void insertBefore(T reference, T item) { - // TODO Auto-generated method stub - throw new UnsupportedOperationException("Unimplemented method 'insertBefore'"); + CustomLinkedListNode referenceNode = traverseFind(head, reference, ItemPosition.CURRENT); + CustomLinkedListNode nodeToInsert = new CustomLinkedListNode<>(referenceNode.getNext(), item); + referenceNode.setNext(nodeToInsert); } @Override public T getAfter(T reference) { - // head represents the last inserted item thus making enrire list in reverse + // head represents the last inserted item thus making entire list in reverse // order CustomLinkedListNode node = traverseFind(head, reference, ItemPosition.BEFORE); return node == null ? null : node.getItem(); @@ -136,7 +144,7 @@ public class CustomLinkedListImpl implements CustomLinkedList { @Override public T getBefore(T reference) { - // head represents the last inserted item thus making enrire list in reverse + // head represents the last inserted item thus making entire list in reverse // order CustomLinkedListNode node = traverseFind(head, reference, ItemPosition.AFTER); return node == null ? null : node.getItem();