Junilu Lacar wrote:You're going down the wrong track with this.
Just think about like this: If you have linked list 1 -> 2 -> 3 -> 4 -> 5 then to create a reversed list from this,
2 -> 1
3 -> 2 -> 1
4 -> 3 -> 2 -> 1
5 -> 4 -> 3 -> 2 -> 1
See how that's done? You only have to traverse the original list the normal way and <do what?> to create a new list that's reversed.
It shouldn't be hard to figure out what <do what?> is...
Junilu Lacar wrote:Note that your requirement (based on what you posted in the other thread) says "and creates a new list..." -- this means that the original list should not be modified; you should create a new list that is the reverse of the original list provided.
Junilu Lacar wrote:Just to make sure I'm not making false assumptions here, your instructor did already discuss or show how to do some basic operations on linked lists, right? Like search for a node, delete a node, append a node, and insert a node, right? Among those four operations, which one do you think is going to be useful to complete this exercise?
Ana Yo wrote:We never really went over the LinkedList methods only the ListNode methods(getValue(),getNext(),setValue(),setNext() )
Nor do you need access to any list nodes. You need a proper add(int, E) method, like this. I would make the list node class a private nested class of the linked list class. I would also make a method to create a reversed list an instance method of the linked list class:-Remember the importance of the documentation comments, which tell you what you what that method does.
Junilu Lacar wrote:. . . You really dont need to go backwards. . . .
Do you mean not at all OO? I agree that outside code shouldn't be able to access a node in a linked list. The add(int, E) method I mentioned does however need access to the appropriate nodes.
Junilu Lacar wrote:. . . is not very OO. . . .