Results 1 to 1 of 1
  1. #1
    falkon114 is offline Member
    Join Date
    Dec 2010
    Posts
    18
    Rep Power
    0

    Default Linking nodes/adding node data

    I need to insert an element into a doubly linked node list. I'm confused, though, with generics.

    The method header I'm working with says public void insertBefore (E placeholder, E data)

    I'm supposed to insert a new element (data) into the position before an element searched for (placeholder).

    I understand how I would go about doing this if placeholder and data were declared as nodes, but I'm rather confused when they're generic E datatypes.

    pseudocode seems like something like this:
    create new Node new
    set new to currentNodes previous
    set new's next to placeholder
    set placeholder's previous to new

    ..something along those lines. Yet I can't quite figure out where to get started setting nodes to generic data types, since that doesn't allow use of .previous and .next ... =/

    this is all I have come up with, and ... yeah.

    Java Code:
        public void insertBefore (E placeholder, E data)
        {
        	
        	Node current = head;
        	Node previous = null;
        	Node temp = null
        	
        	while (current != null && !current.containsData(placeholder))
            {
                previous = current;
                current = current.next;
                
            }
        	
            if(current.containsData(placeholder))
            {
            	current.previous.next=;
            	previous.next = temp;
            }
        	
        	
        }
    Last edited by falkon114; 04-19-2011 at 10:48 PM.

Similar Threads

  1. Replies: 0
    Last Post: 11-29-2010, 02:27 AM
  2. Replies: 6
    Last Post: 10-09-2010, 01:30 AM
  3. Adding a node with a TreeViewer; what's wrong?
    By Rodrigo Braz in forum SWT / JFace
    Replies: 1
    Last Post: 04-24-2009, 08:43 AM
  4. Adding/removing nodes to tree under TreeViewer
    By Rodrigo Braz in forum SWT / JFace
    Replies: 0
    Last Post: 04-20-2009, 02:02 AM
  5. How to Transmit data from one node to another
    By swimberl in forum Networking
    Replies: 2
    Last Post: 01-04-2008, 09:48 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
  •