Study Guide
Study Guide
while (current!=null) {
newCurrent.next = new Node<>(current.data);
current=current.next;
newCurrent=newCurrent.next;
}
result.head = dummy.next;
result.size = size;
return result;
}
public void add2(int index, E item) {
if (index < 0) {
throw new IndexOutOfBoundsException(Integer.toString(index));
}
if (index == 0) {
head = new Node(item, head);
size++;
} else {
int i = index;
Node<E> current = head;
while (current != null && --i > 0) {
current = current.next;
}
if (current != null && i == 0) {
current.next = new Node(item, current.next);
size++;
} else {
throw new IndexOutOfBoundsException(Integer.toString(index));
}
}
}
public void add (int index, E item) {
if (index < 0 || index > size) {
throw new
IndexOutOfBoundsException(Integer.toString
(index));
}
if (index == 0) {
addFirst(item);
} else {
Node<E> node = getNode(index-1);
addAfter(node, item);
}
}
Boolean hasDuplicates(){
If (head == null){
Return False}
Node current = head;
While node(current!= null){
Node inner = current.next;
While(inner != null){
if (current.data.equals(inner.data){
Return True
}
Inner = inner.next;
{
Current = current.next;
}
}