Can anyone help with java? Finding common nodes from two linked lists using recursion

Posted by Dan on Stack Overflow See other posts from Stack Overflow or by Dan
Published on 2010-04-25T06:25:46Z Indexed on 2010/04/25 6:33 UTC
Read the original article Hit count: 238

Filed under:
|

I have to write a method that returns a linked list with all the nodes that are common to two linked lists using recursion, without loops.

For example,

first list is 2 -> 5 -> 7 -> 10

second list is 2 -> 4 -> 8 -> 10

the list that would be returned is 2 -> 10

I am getting nowhere with this.. What I have been think of was to check each value of the first list with each value of the second list recursively but the second list would then be cut by one node everytime and I cannot compare the next value in the first list with the the second list. I hope this makes sense...

Can anyone help?

© Stack Overflow or respective owner

Related posts about java

Related posts about recursion