1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Java LinkedListNode class

  1. Mar 21, 2008 #1
    [SOLVED] Java LinkedListNode class


    I'm trying to understand a generic linked list...in Java.

    I understand that I should have a LinkedList class containing a Node class.
    The Node class should have an info variable and a link variable.These variables should be accesessed through the .dot operator.

    Now my book has a huge chapter on it,but unfortunately introducing generics and Linked Lists with a million different interfaces isn't much use to a noob.

    My biggest problem seems to be in understanding how a node is inserted in to the list.
    For example the book shows a Node constructor having the following parameters:
    (T elem,LinkedList<T> ptr)...I understand that T can be anything except primitive type parameters.But what I don't understand is in what context will this method be used??

    Most likely we will be required to squash an array of Integer or String values into a linked list...So assuming that I have this : Integer[] anArray={1},{2},{3},{4}
    How would I go about constructing nodes with these values...The constructor has a parameter,LinkedList<T> ptr.Where am I intended to get this reference variable from.

    Attached Files:

    Last edited: Mar 21, 2008
  2. jcsd
  3. Mar 21, 2008 #2
    I don't know a thing about Java because I prefer C++'s transparency so I'll just say that your assessment of a linked list is accurate. When you implement a linked list, it's important to create a "root" pointer that points to the first element of your list, then use a temp variable to create subsequent nodes by repeated use of the "new" command.
    Last edited: Mar 21, 2008
  4. Mar 22, 2008 #3
    I think I just might get it now...
  5. Mar 22, 2008 #4
    Yay!I do...Marked as solved!!
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?

Similar Discussions: Java LinkedListNode class
  1. Java class Arrays (Replies: 1)