Results 1 to 13 of 13
Like Tree3Likes
  • 1 Post By KevinWorkman
  • 2 Post By JosAH

Thread: Linked lists

  1. #1
    Malv is offline Member
    Join Date
    Jun 2013
    Posts
    62
    Rep Power
    0

    Default 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;
    }
    }
    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
    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 03:17 PM.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,520
    Blog Entries
    7
    Rep Power
    20

    Default Re: Linked lists

    Asking us to do your homework is cheating.

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,004
    Rep Power
    6

    Default 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

  4. #4
    Malv is offline Member
    Join Date
    Jun 2013
    Posts
    62
    Rep Power
    0

    Default Re: Linked lists

    Quote Originally Posted by gimbal2 View Post
    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.

  5. #5
    Malv is offline Member
    Join Date
    Jun 2013
    Posts
    62
    Rep Power
    0

    Default Re: Linked lists

    Quote Originally Posted by JosAH View Post
    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.

  6. #6
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,004
    Rep Power
    6

    Default Re: Linked lists

    Quote Originally Posted by Malv View Post
    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.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,520
    Blog Entries
    7
    Rep Power
    20

    Default Re: Linked lists

    Quote Originally Posted by Malv View Post
    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
    cenosillicaphobia: the fear for an empty beer glass

  8. #8
    Malv is offline Member
    Join Date
    Jun 2013
    Posts
    62
    Rep Power
    0

    Default Re: Linked lists

    Quote Originally Posted by JosAH View Post
    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.

  9. #9
    Malv is offline Member
    Join Date
    Jun 2013
    Posts
    62
    Rep Power
    0

    Default Re: Linked lists

    Quote Originally Posted by Malv View Post
    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;
    }
    }
    (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.



    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;
    }
    Any feedback regarding the code above is logical?

  10. #10
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,960
    Rep Power
    8

    Default 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.
    doWhile likes this.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  11. #11
    Malv is offline Member
    Join Date
    Jun 2013
    Posts
    62
    Rep Power
    0

    Default 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 View Post
    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.

  12. #12
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,602
    Rep Power
    5

    Default Re: Linked lists

    Quote Originally Posted by Malv View Post
    You belongs to this forum
    So do you and so do all the other members.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  13. #13
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,520
    Blog Entries
    7
    Rep Power
    20

    Default Re: Linked lists

    I banned the OP for a week so s/he can cool down.

    kind regards,

    Jos
    DarrylBurke and KevinWorkman like this.
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. help with linked lists
    By akusa in forum New To Java
    Replies: 1
    Last Post: 04-15-2013, 04:34 AM
  2. Linked Lists
    By ashplusham in forum New To Java
    Replies: 3
    Last Post: 11-20-2012, 08:05 PM
  3. Linked Lists
    By Dee in forum New To Java
    Replies: 18
    Last Post: 02-02-2011, 03:14 AM
  4. Linked Lists
    By vendetta in forum New To Java
    Replies: 6
    Last Post: 01-26-2010, 08:23 AM
  5. Single linked lists - help
    By Srcee in forum New To Java
    Replies: 10
    Last Post: 10-29-2009, 05:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •