title: Reversing a singly linked list iteratively
body: <p>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?</p>
  
  <pre><code>public void invert() {
      if (this.getHead() == null)
          return;
      if (this.getHead().getNext() == null)
          return;
      //this method should reverse the order of this linked list in O(n) time
      Node&lt;E&gt; prevNode = this.getHead().getNext();
      Node&lt;E&gt; nextNode = this.getHead().getNext().getNext();
      prevNode.setNext(this.getHead());
      this.getHead().setNext(nextNode);
      nextNode = nextNode.getNext();
  
      while (this.getHead().getNext() != null)
      {
          this.getHead().getNext().setNext(prevNode);
          prevNode = this.getHead().getNext();
          this.getHead().setNext(nextNode);
          if (nextNode != null)
              nextNode = nextNode.getNext();
      }
      this.head = prevNode;
  }
  </code></pre>