4 Replies Latest reply: Sep 1, 2009 6:34 PM by 843853

One direction list object problem, need to inverse the numbers in it.

public class Node {
public int number;
public Node next;
}

By this object, I need to make the inverse of this array from this:
{1,2,3,4,5,6,7,8,9}

to make it like this:
{9,8,7,6,5,4,3,2,1}

can some one help me please to solve this problem?

Thank's!
• 1. Re: One direction list object problem, need to inverse the numbers in it.
What have you tried so far? Under what limitations are you working? For example, can you modify the Node class?
• 2. Re: One direction list object problem, need to inverse the numbers in it.
This is the node class, this all what I have in the question.
And I really don't have nothing so far,

could you help me with this?
It's very important to me.
• 3. Re: One direction list object problem, need to inverse the numbers in it.
gozal wrote:
This is the node class, this all what I have in the question.
And I really don't have nothing so far,

could you help me with this?
It's very important to me.
This isn't enough information for me to help you. I would look into writing a Comparator for the Node class.
• 4. Re: One direction list object problem, need to inverse the numbers in it.
I am just guessing, but I think the OP's instructor wants him to use recursion to construct a copy of the list reversed. Notice that number is a public member of the class, so Node p = new Node(); p.number = last.number; is valid and you don't have modify Node.