# Linked lists

Printable View

• 08-15-2013, 01:00 PM
Malv
Linked lists
Consider the following class, which can be used to construct linked lists:
Code:

```public class Node { public int value; public Node next; public Node(int value, Node next) { this.value = value; this.next = next; } }```
Note: All parts of this question assume that a linked list is represented directly
as a sequence of nodes, without using a separate LinkedList wrapper class.
(a) Write an iterative method that takes a linked list as a parameter, and returns
an array containing the integer values of all its elements.

So I just create an array and store the linked list item one by one into the array? and return the array?

(b) Write a recursive method which returns a new linked list containing all the
values of the supplied list, in reverse order. It should have the following
signature:
public Node reverse(Node first)
You may write additional helper methods if you find it useful to do so.

Anyone can show any example of recursion linked list java codes?
Edit : Ask for some help yet some mod comment some constructive feedback.

This is what I found by myself from what you called the internet
Code:

```public Node reverse(Node first){     if (first== null) return null;     if (first.next== null) return list;     Node second = first.next;     first.next = null;     Node reverseRest = reverse(second);     second.next = first;     return reverseRest; }```
• 08-15-2013, 01:30 PM
JosAH
Re: Linked lists
Asking us to do your homework is cheating.

Jos
• 08-15-2013, 01:46 PM
gimbal2
Re: Linked lists
Hey just answering the questions is not helping with the homework. Don't judge him just yet Dredd.

"So I just create an array and store the linked list item one by one into the array? and return the array?
Yep, that's exactly what it said.

"Anyone can show any example of recursion linked list java codes?"
Yes, but that would require to post code which you can abuse to directly solve whatever homework you have to do without understanding it and that's not what a forum is for. Alternatively, might you be interested in learning what recursion is exactly perhaps, so you may attempt to work it out yourself?
• 08-15-2013, 02:13 PM
Malv
Re: Linked lists
Quote:

Originally Posted by gimbal2
Hey just answering the questions is not helping with the homework. Don't judge him just yet Dredd.

"So I just create an array and store the linked list item one by one into the array? and return the array?
Yep, that's exactly what it said.

"Anyone can show any example of recursion linked list java codes?"
Yes, but that would require to post code which you can abuse to directly solve whatever homework you have to do without understanding it and that's not what a forum is for. Alternatively, might you be interested in learning what recursion is exactly perhaps, so you may attempt to work it out yourself?

Thanks gimbal for the constructive feedback. Really appreciate it. Unlike some mod.
• 08-15-2013, 02:16 PM
Malv
Re: Linked lists
Quote:

Originally Posted by JosAH
Asking us to do your homework is cheating.

Jos

And by the way, this isn't a homework to begin with. Just want to clarify my understanding of the question.
• 08-15-2013, 02:21 PM
gimbal2
Re: Linked lists
Quote:

Originally Posted by Malv
And by the way, this isn't a homework to begin with. Just want to clarify my understanding of the question.

Generally you pose that to the person who asked the questions in the first place.
• 08-15-2013, 02:32 PM
JosAH
Re: Linked lists
Quote:

Originally Posted by Malv
And by the way, this isn't a homework to begin with. Just want to clarify my understanding of the question.

By asking us to answer those questions? Funny interpretation of 'clarifying your understanding'; b.t.w. it's no use to report my reply as rude; it wasn't and you were trying to cheat.

Jos
• 08-15-2013, 03:10 PM
Malv
Re: Linked lists
Quote:

Originally Posted by JosAH
By asking us to answer those questions? Funny interpretation of 'clarifying your understanding'; b.t.w. it's no use to report my reply as rude; it wasn't and you were trying to cheat.

Jos

Which part did I ask you to answer those questions? I know that you're a mod itself and you think you're the boss here. Fine, I got my objective.
• 08-15-2013, 03:19 PM
Malv
Re: Linked lists
Quote:

Originally Posted by Malv
Consider the following class, which can be used to construct linked lists:
Code:

```public class Node { public int value; public Node next; public Node(int value, Node next) { this.value = value; this.next = next; } }```
(b) Write a recursive method which returns a new linked list containing all the
values of the supplied list, in reverse order. It should have the following
signature:
public Node reverse(Node first)
You may write additional helper methods if you find it useful to do so.

Code:

```public Node reverse(Node first){     if (first== null) return null;     if (first.next== null) return list;     Node second = first.next;     first.next = null;     Node reverseRest = reverse(second);     second.next = first;     return reverseRest; }```

Any feedback regarding the code above is logical?
• 08-15-2013, 03:21 PM
KevinWorkman
Re: Linked lists
Malv, this is technical forum. We don't really have time for childish bickering and constant reporting of things to pursue some perceived vendetta. Move on.

This is the internet. People are welcome to post whatever they want. Jos was correct in telling you that asking us to do your homework for you was cheating. If this isn't homework, fine, move on. Better yet you could have replied with more information about what you were confused about.

But you're wasting everybody's time by continuing to bicker and report things that aren't worth looking into. The mods have actual spam and abuse to deal with, and reporting Jos over and over again is simply going to annoy us and make it harder for us to do our "jobs", which we do for free in our spare time. Consider this a warning.
• 08-15-2013, 03:28 PM
Malv
Re: Linked lists
JosAH is the one with the vendetta. Every single thread i post, he's bent on commenting things which isn't correspond with the thread topic.
You belongs to this forum, definitely you will help your fellow mods out. Like you said, this is the internet. Free speech. So you expect me to suck it up? While the one who start all this vendetta is scot free?

Quote:

Originally Posted by KevinWorkman
Malv, this is technical forum. We don't really have time for childish bickering and constant reporting of things to pursue some perceived vendetta. Move on.

This is the internet. People are welcome to post whatever they want. Jos was correct in telling you that asking us to do your homework for you was cheating. If this isn't homework, fine, move on. Better yet you could have replied with more information about what you were confused about.

But you're wasting everybody's time by continuing to bicker and report things that aren't worth looking into. The mods have actual spam and abuse to deal with, and reporting Jos over and over again is simply going to annoy us and make it harder for us to do our "jobs", which we do for free in our spare time. Consider this a warning.

• 08-15-2013, 03:34 PM
jim829
Re: Linked lists
Quote:

Originally Posted by Malv
You belongs to this forum

So do you and so do all the other members.

Regards,
Jim
• 08-15-2013, 03:36 PM
JosAH
Re: Linked lists
I banned the OP for a week so s/he can cool down.

kind regards,

Jos