+ 3

LinkedList Java

Hi, I got the exercise to write java code using Linked Lists. It says: "You can use the following node definition for this example: type Node = { int value Node next } The following recursive algorithm printReversed ( ↓ Node n) returns a list (where n is the Starting node is) upside down (for the above list would be the sequence of numbers 5 4 3 2 1 are output). printReversed (↓ Node n) { if (n! = null) { print reversed (↓ n.next) write (↓ n.value) } } " This is just part of it, that is unclear to me. Now, I need to convert this "pseudo code" to java code, and to modify printReversed(). That wouldn't be problem if I would know how to convert this type Node thingy to java, I know it should be done with new class Node and its constructor but it gives me error when calling method "String cannot be converted to Node". I'm short on time so please help. 😁😁

26th May 2018, 11:37 AM
Amar
Amar - avatar
2 Respostas
+ 3
Could you show the code?
26th May 2018, 6:10 PM
Christopher Dorado
Christopher Dorado - avatar
+ 2
Nevermind, I managed to do it with 2 constructors. Thanks for offering for help.
27th May 2018, 8:05 AM
Amar
Amar - avatar