java - Linkedlist recursive method -
I am trying to write a recursive method which prints the linked list in reverse, but I get a stack overflow error is. When the last element of the array reaches the law, then the method should be abolished, and it will have to restrain the method to be called back, and then that method will be printed and it will be returned to someone coming back.
Public Zero Print (node node) {if (node.next! = Null) print (node.next); System.out.println ("+ + node.value +" ");}
Convert your code to
public zero in print (node node) {System.out.println ("+ + node.value +" "); If (node.exe! = Null) print (node. Nxt); } If it still fails with one exception, it means that you have a cyclical linked list if If this is not a failure, it means that you are filling your app with fixed default memory heap, you can try to increase the size of the pile to make sure that it fixes the issues < / Ol> Once you locate the problem, you restore the original code President can. If you want information on how to increase the Hep size, see this link
Comments
Post a Comment