I am working on an assignment that forces me to write a java program to print in the reverse order of the data contained in a linked list using recursion. So far this is what I have, it works, but only on the last item in the IE list. it stops when it prints the last item.
public String reverse(IntNode head){
String result = "";
if(head.getLink() == null){
result += head.getData();
return result;
}
else if(head.getLink().getLink() == null){
result += head.getLink().getData();
head.removeNodeAfter();
return result;
}
else{
return reverse(head.getLink());
}
}
How do I get it to continue browsing the list behind the recursive tree?
Viper344
source
share