The source code in java for getting an element from a linked list using an index
public E get(int index) {
checkElementIndex(index);
return node(index).item;
}
and the code for node()
Node<E> node(int index) {
// assert isElementIndex(index);
if (index < (size >> 1)) {
Node<E> x = first;
for (int i = 0; i < index; i++)
x = x.next;
return x;
} else {
Node<E> x = last;
for (int i = size - 1; i > index; i--)
x = x.prev;
return x;
}
}
I can't understand why bitshift operator is used in the if condition. Can someone please explain?