Page 1 of 1

## 2 Replies - 588 Views - Last Post: 10 March 2013 - 06:39 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=314917&amp;s=37903c081dd5a2597ec07ba3f66d7261&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 Doughboy123

Reputation: 0
• Posts: 14
• Joined: 02-October 12

Posted 09 March 2013 - 11:10 PM

Hi all,

I want to write a method to recursively reverse a linked list.
I have been working on it for awhile but I haven't been able to get very far on it.

Here is the code I have so far:
```public Node recursiveThisList(Node previous, Node current){
if(previous == null)
return null;
previous.setNext(null);
}
if(current == null){
}else{
Node temp = current.getNext();
current.setNext(previous);
reverseR(current, temp);
}
return null;

```

Is there a way to do this with a void method and without any parameters: public void recursiveThisList().
Thanks.

Is This A Good Question/Topic? 0

## Replies To: Recursion Linked List

### #2 GregBrannon

• D.I.C Lover

Reputation: 2249
• Posts: 5,340
• Joined: 10-September 10

Posted 10 March 2013 - 01:29 AM

A swapNode() method might be useful, then begin at one end, swap ends, move to next node, swap n + 1 with end - 1, and continue until reaching the middle. I would also include the word "reverse" in the title of your method.

### #3 baavgai

• Dreaming Coder

Reputation: 6578
• Posts: 13,908
• Joined: 16-October 07

Posted 10 March 2013 - 06:39 AM

Doughboy123, on 10 March 2013 - 01:10 AM, said:

Is there a way to do this with a void method and without any parameters: public void recursiveThisList().

Not really. At least, not in your case. However, no rules against a method overload:
```public void recursiveThisList() {
}

private void recursiveThisList(Node node){