java - Why is head.data = 0 when head.next == null? -


Working assignments on the HW assignment is to revert to a linked list repeatedly. I do not understand that my system.out.println (head.data) line head.data as always 0 Why does print Assuming that I enter 4,5,6 (For this work, enter fill and reading methods, if I put a print in my last, then it shows that the head is still 4 , 5, 6) and Head.next is zero , that does not mean that is head.data is equal to 6 ? I know that I am getting many other problems while trying to reverse it, but I do not understand why head.next is null the Head.data is 0. I thought head.next was the next item in the list, not currently.

  Reverse public fixed node (node ​​head) {node n = node node (); If (head == zero) {return n; } And if (head.next == faucet) {System.out.println (head.data); N.data = head.data; Head.next = null; N.next = reverse (head.next); Return n; } And {reverse (head.next); Return n; }}    

lower:

  node n = New node (); If (head == zero) {return n; }   

The result is the default value of the data as a single element list of an empty list (potentially zero?)

apart from Last, other is not right, because it does nothing to n before returning.

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -