Results 1 to 4 of 4
  1. #1
    tjoney is offline Member
    Join Date
    Feb 2011
    Posts
    2
    Rep Power
    0

    Default Linked List Help

    I am new to Java programming and my instructor has assigned us the task of writing our own linked list class and told us to construct an insertAt method. I am have problems getting it to work. Any help would be appreciated.




    public class NodeLinkedList
    {
    private IntegerNode head;

    private IntegerNode tail;

    private int numberOfItems;

    public NodeLinkedList()
    {
    head = null;

    tail = null;

    numberOfItems = 0;
    }

    public int getNumberOfItems()
    {
    return numberOfItems;
    }

    public void insert( int value )
    {
    IntegerNode n = new IntegerNode ( value );
    n.setNext( head );
    head = n;
    numberOfItems ++;
    }

    public void insertAt(int index, int value)
    {
    IntegerNode n1 = new IntegerNode ( value );

    if ( n1 == null )
    {
    N.next = head;
    head = N;
    }
    else
    {
    N.next = n1.next;

    }
    }
    }
    Attached Files Attached Files

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,785
    Rep Power
    7

    Default

    Quote Originally Posted by tjoney View Post
    I am have problems getting it to work.
    Really? Any chance you provide us with more information than that?

    Java Code:
    IntegerNode n1 = new IntegerNode ( value );
    if ( n1 == null )
    Since you just created a new object and assigned it to n1 it is impossible for this if statement to be true.

  3. #3
    tjoney is offline Member
    Join Date
    Feb 2011
    Posts
    2
    Rep Power
    0

    Default

    Quote Originally Posted by Junky View Post
    Really? Any chance you provide us with more information than that?

    Java Code:
    IntegerNode n1 = new IntegerNode ( value );
    if ( n1 == null )
    Since you just created a new object and assigned it to n1 it is impossible for this if statement to be true.
    The compiler says it cannot find symbol Node. Why would that be impossible? Any chance you can provide more information than that?

    Also I appreciate your sarcasm. It makes learning and asking questions really NICE.
    Last edited by tjoney; 02-18-2011 at 01:10 AM.

  4. #4
    doWhile is offline Moderator
    Join Date
    Jul 2010
    Location
    California
    Posts
    1,642
    Rep Power
    7

Similar Threads

  1. Need help using linked list
    By tigertomas in forum New To Java
    Replies: 5
    Last Post: 02-12-2011, 03:22 PM
  2. help with linked list
    By Yakg in forum New To Java
    Replies: 7
    Last Post: 01-24-2011, 06:40 PM
  3. Linked list inside a linked list
    By viperlasson in forum New To Java
    Replies: 5
    Last Post: 07-26-2010, 11:15 PM
  4. Linked List
    By basma in forum JCreator
    Replies: 0
    Last Post: 02-03-2010, 08:34 AM
  5. Linked List integer list
    By igniteflow in forum Advanced Java
    Replies: 1
    Last Post: 12-10-2008, 08:53 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
  •