I am trying to move backwards to an index in a Doubly Linked List if the desired index is in the latter half of the list. What I have now compiles but does not work properly. Can anyone diagnose the issue here? I am guessing it is somewhere in the loop logic.
private Node<E> goToNode(int index) {
Node<E> temp;
double whichHalf = size / 2;
if(index > whichHalf) {
temp = tail.prev;
for(int i = size; i > index; i--)
temp = temp.prev;
return temp;
}
else {
temp = head.next;
for(int i = 0; i < index; i++)
temp = temp.next;
return temp;
}
}
Thanks!