LinkedList Iterator Java tips

  • Comp Sci
  • Thread starter Live4eva_2
  • Start date
  • #1
Live4eva_2
28
0
Hi I'm struggling to create a DoublyLinkedList<T> class in Java.
Well,it's actually the iterator that's 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 can't 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
Live4eva_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 don't think that it could be a problem with instantiating the iterator object.
 
  • #3
Defennder
Homework Helper
2,592
5

Suggested for: LinkedList Iterator Java tips

  • Last Post
Replies
7
Views
756
Replies
17
Views
666
  • Last Post
Replies
5
Views
1K
  • Last Post
Replies
12
Views
756
  • Last Post
Replies
7
Views
800
  • Last Post
Replies
1
Views
505
Replies
2
Views
619
  • Last Post
Replies
2
Views
635
  • Last Post
Replies
4
Views
1K
Replies
11
Views
458
Top