LinkedList Iterator Java tips

  • Comp Sci
  • Thread starter Live4eva_2
  • Start date
  • #1
28
0
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.
 

Answers and Replies

  • #2
28
0
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.
 

Related Threads on LinkedList Iterator Java tips

  • Last Post
Replies
3
Views
4K
Replies
0
Views
831
  • Last Post
Replies
14
Views
787
  • Last Post
Replies
24
Views
3K
  • Last Post
Replies
2
Views
1K
  • Last Post
Replies
6
Views
708
  • Last Post
2
Replies
29
Views
2K
Replies
37
Views
2K
  • Last Post
Replies
4
Views
4K
  • Last Post
Replies
3
Views
1K
Top