Question: Can someone help me with these functions. The code is not running. Removes the element at the specified position in this list. Shifts any subsequent
Can someone help me with these functions. The code is not running. Removes the element at the specified position in this list. Shifts any subsequent elements to the left.
public E remove(int index) { if (index < 0 || index >= size) { throw new IndexOutOfBoundsException(); } if (index == 0) { E value = head.value; head = head.next; size--; return value; } Node previous = (Node) get(index - 1); Node current = previous.next; previous.next = current.next; size--; return (E) current.value; } Appends the specified element to the end of this list.
public boolean add(E e) { Node newNode = new Node(e, null, tail); if (tail == null) { head = newNode; } else { tail.next = newNode; } tail = newNode; size++; return true; } Removes the first occurrence of the specified element from this list, if it is present. If this list does not * contain the element, it is unchanged. Returns {@code true} if this list contained the specified element. public boolean remove(Object o) { return false; }
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
