Results 1 to 13 of 13
Thread: Linked lists
- 08-15-2013, 02:00 PM #1
Member
- Join Date
- Jun 2013
- Posts
- 62
- Rep Power
- 0
Linked lists
Consider the following class, which can be used to construct linked lists:
Java Code:public class Node { public int value; public Node next; public Node(int value, Node next) { this.value = value; this.next = next; } }
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
Java 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; }
Last edited by Malv; 08-15-2013 at 04:17 PM.
- 08-15-2013, 02:30 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
Re: Linked lists
Asking us to do your homework is cheating.
JosBuild a wall around Donald Trump; I'll pay for it.
- 08-15-2013, 02:46 PM #3
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 13
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?"Syntactic sugar causes cancer of the semicolon." -- Alan Perlis
- 08-15-2013, 03:13 PM #4
Member
- Join Date
- Jun 2013
- Posts
- 62
- Rep Power
- 0
- 08-15-2013, 03:16 PM #5
Member
- Join Date
- Jun 2013
- Posts
- 62
- Rep Power
- 0
- 08-15-2013, 03:21 PM #6
Just a guy
- Join Date
- Jun 2013
- Location
- Netherlands
- Posts
- 5,114
- Rep Power
- 13
- 08-15-2013, 03:32 PM #7
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
- 08-15-2013, 04:10 PM #8
Member
- Join Date
- Jun 2013
- Posts
- 62
- Rep Power
- 0
- 08-15-2013, 04:19 PM #9
Member
- Join Date
- Jun 2013
- Posts
- 62
- Rep Power
- 0
- 08-15-2013, 04:21 PM #10
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.How to Ask Questions the Smart Way
Static Void Games - GameDev tutorials, free Java and JavaScript hosting!
Static Void Games forum - Come say hello!
- 08-15-2013, 04:28 PM #11
Member
- Join Date
- Jun 2013
- Posts
- 62
- Rep Power
- 0
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?
- 08-15-2013, 04:34 PM #12
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 15
Re: Linked lists
The JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
- 08-15-2013, 04:36 PM #13
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
Similar Threads
-
help with linked lists
By akusa in forum New To JavaReplies: 1Last Post: 04-15-2013, 05:34 AM -
Linked Lists
By ashplusham in forum New To JavaReplies: 3Last Post: 11-20-2012, 09:05 PM -
Linked Lists
By Dee in forum New To JavaReplies: 18Last Post: 02-02-2011, 04:14 AM -
Linked Lists
By vendetta in forum New To JavaReplies: 6Last Post: 01-26-2010, 09:23 AM -
Single linked lists - help
By Srcee in forum New To JavaReplies: 10Last Post: 10-29-2009, 06:35 PM
Bookmarks