In the first part I’ve described how to reverse single LinkedList using recursion. Today we will to do the same using one loop.
The structure of linked list will be the same, look to the Node class.
OK, What we should understand? The first implementation used next steps:

• Go throughout all nodes and set next to null { after these steps we have n-null pointed LinkedLists.}

Current implementation will have different approach and will be implemented using next steps:

• Create reversed root node.
• Save as next reversed root.
• Set node to reversed root.
• Set next node to node; {For making loop}.

Steps are good but example better 🙂, So, we have next list:

`1->2->3->4->null`

First algorithm {recursion implementation} works using two-time loop {recursion} from start to end and from end to start , it’s like recursion working.

So, After first time loop {recursion from start to end} we will have n-lists:

`1->null; 2->null; 3->null; 4->null;`

During second time loop {recursion from end to start } we add

`n-1->n-2`

elements and will have reversed list

`4->3->2->1->null`

and on the start of second loop {recursion from end to start } we have first element of reversed list and just add new elements to end .

So, what is different to current implementation ?

We have the same list:

`1->2->3->4->null`

and we have just a one loop. So, the main different is changing root element of reversed list. In other words new element will be added to head or better to new element will be added tail of reversed list.

Explanation of above steps:

We have root of reversed list

`reversedList = null`

read first element and add tail {reversedList} as next to first element after it assign first element as tail to {reversedList} for next loop iteration, so we will have

`reversedList = 1->null`

after second iteration will have

`reversedList = 2->1->null`

and so on.

Code:

```package com.alychidesigns.list.reverse;

import com.alychidesigns.list.Node;

/**
*@author
*/
public class LoopReverser implements Reverser {
@Override
public Node reverse(Node node) {
Node prev = null;
while (node!=null){
Node next = node.getNext();
node.setNext(prev);
prev = node;
node = next;
}
return prev;
}
}```

Pros:

• Faster than first implementation because use one loop from start to end
• Do not use Stack Memory

Cons:

• Hard to understand for some people {because use diff approach than recursion and stack}