1. Limited time only! Sign up for a free 30min personal 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!

LinkedList Iterator Java tips

  1. May 16, 2008 #1
    Hi I'm struggling to create a DoublyLinkedList<T> class in Java.
    Well,it's actually the iterator thats freaking me out..
    Most tutorials and documents I've read use three classes for this:Node<T>,DoublyLinkedList<T> and LinkedListIterator<T>.

    I can see the point in creating Node and DoublyLinkedList<T> classes but i don't know why I cant simply just include the 2 iterator reference variables(next and previous) in the DoublyLinkedList<T> class instead of writing an additional iterator class.
  2. jcsd
  3. May 19, 2008 #2
    OK nevermind that..Let me pose another question:
    public class LinkedList<T>
    public Node<T> first;
    public Node<T> last;
    protected class Node<T>
    public Node<T> next;
    public Node<T> last;

    public class Iterator<T>
    protected Node<T> current;
    protected Node<T> previous;


    I've only included the classes and variables in order to illustrate the visibility.
    when I complile I'm getting the msg that "Node<T> current" isn't available in LinkedList<T> class...why not !?Am I only allowed one inner class?Also i ensured that my iterator was constructed within the LinkedList constructor so i dont think that it could be a problem with instantiating the iterator object.
  4. May 19, 2008 #3


    User Avatar
    Homework Helper

Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Discussions: LinkedList Iterator Java tips
  1. Java program (Replies: 3)

  2. Java prob. (Replies: 1)

  3. HeapSort Java (Replies: 3)

  4. Iterative Circuit (Replies: 14)