|
|
@ -125,4 +125,29 @@ public class SimpleLinkedList<E> extends AbstractSimpleList<E> { |
|
|
|
} |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
public void add(int i, E e) throws IndexOutOfBoundsException { |
|
|
|
if (size == 0) { |
|
|
|
if (i != 0) { |
|
|
|
throw new IndexOutOfBoundsException("Index " + i + " is out of bounds!"); |
|
|
|
} |
|
|
|
set(0, e); |
|
|
|
|
|
|
|
} else if (size > 0) { |
|
|
|
if (i == size) { |
|
|
|
add(e); |
|
|
|
} |
|
|
|
|
|
|
|
} else if (size > 0 && i < size) { |
|
|
|
Node<E> newNode = new Node<>(e); |
|
|
|
|
|
|
|
Node<E> tempNode = getIndex(i); |
|
|
|
Node<E> preTempNode = getIndex(i).getPredecessor(); |
|
|
|
|
|
|
|
preTempNode.setSuccessor(newNode); |
|
|
|
newNode.setPredecessor(preTempNode); |
|
|
|
newNode.setSuccessor(tempNode); |
|
|
|
tempNode.setPredecessor(newNode); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|