Recursion through a linked list in Java -


I need a method code that prints the contents of the linked list repeatedly, though my method Not working.

Public Linkedist Reverse () (Linked List List = New Linkedist); List = reverse reactions (list, 0); Return list; } Public Linkedlist reverse reactions (linked list, int pauses) {if (pos! = Size ()) {rotate (); List.add (find ()); Pos = Pos + 1; Reverse curling (list, position); } Return list; } Public string toring () {string result = "list list: {"; Result = toStringRecursion (result, 0); Return result; } Private string toStringRecursion (string result, int pos) {if (pos! = Size ()) {rotate (); String Temporary = Results + (Received) GetData () + ","; Pos = Pos + 1; ToStringRecursion (Temp, pos); } Return results; }

The reverse function is working fine, however, even though my toString passed the previous result as only a parameter, the initial result was "List of list: {"} Showing in If I print the result passed through toStringRecursion every time, I can see the desired output back before it returns, when the return line reaches.

You have to add the string to the return value. But in this case, using StringBuilder is what you want to do. It is not good for performance because "+" makes it a new string instance called it every time.

  public string toString () {StringBuilder sb = new StringBuilder ("List list: {"}; Annex (SB, 0); Return sb.toString (); } Private Wide Anderson (StringBilder Result, Int Pot) {if (pos! = Size ()) {rotate (); Result.append (get ()) GetData ().) Attached (","). Pos = Pos + 1; Attachment (result, status); }}  

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -