I'm trying to write a recursive method that prints a linked list in reverse but I get a stackoverflow error. The method should terminate when the last element of the array has been reached, and return control to the method that called it, and then that method will print and return to the one that called it and so forth.
public void print(Node node){
if(node.next != null)
print(node.next);
System.out.println(" " + node.value + " ");
}
Convert your code into
public void print(Node node){
System.out.println(" " + node.value + " ");
if(node.next != null)
print(node.next);
}
Once you figure out the issue, you can restore the original code.If you want info on how to increase heap size, check out this link
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.