Results 1 to 3 of 3
  1. #1
    ravinda is offline Member
    Join Date
    Apr 2009
    Posts
    4
    Rep Power
    0

    Default How to link a Array elemant to a Linked list Node

    i just want to link a Array elemant to a linked list node.this structure was in the book Data Structures And Algorithms in Java By Adam Drozdek page 106. icant palce the link here. so sorry.
    after that i can do the other things with nodes. can any one help me on this matter.:confused:

  2. #2
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    Misunderstanding of concept here I think. You don't "link an array element to a linked list node", you put whatever is in the array element into the node instead.

    Java Code:
    public class LLNode {
    
        private Object value;
        private LLNode next;
        private LLNode previous;
    
        public void insertAfter(LLNode node, Object value) {
            LLNode n = new LLNode();
            n.value = value;
            n.previous = node;
            n.next = node.next;
            node.next.previous = n;
            node.next = n;
        }
    
        public Object remove() {
            next.previous = previous;
            previous.next = next;
            return value;
        }
    }
    For a complete implementation see java.util.LinkedList
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  3. #3
    ravinda is offline Member
    Join Date
    Apr 2009
    Posts
    4
    Rep Power
    0

    Default

    not clear yet . here is a link to a picture what i want to implemant.
    imagevisit.com/images/g1lt6y6adiikdbxautg9.jpeg

Similar Threads

  1. linked list or array?
    By sick_peng in forum New To Java
    Replies: 6
    Last Post: 04-15-2009, 07:33 PM
  2. Linked List integer list
    By igniteflow in forum Advanced Java
    Replies: 1
    Last Post: 12-10-2008, 08:53 PM
  3. Linked List help
    By neobie in forum New To Java
    Replies: 8
    Last Post: 12-22-2007, 03:15 AM
  4. Link List
    By one198 in forum New To Java
    Replies: 0
    Last Post: 10-14-2007, 01:33 PM
  5. Help with linked list
    By trill in forum New To Java
    Replies: 1
    Last Post: 08-07-2007, 07:29 AM

Posting Permissions

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