Has to be O(n) and in-place (space complexity of 1). The code below does work, but is there a simpler or better way?
public void invert() { if (this.getH
Edited to remove the extra comparison per iteration:
public void invert() { Node<E> prev = null, next = null;; if (head == null) return; while (true) { next = head.getNext(); head.setNext(prev); prev = head; if (next == null) return; head = next; } }