JavaAlgorithms
Elementary and no so elementary Java algorithms
|
00001 00009 package listAlgorithms; 00010 00011 import java.util.Iterator; 00012 00023 public class ListNodeIterator<T extends Comparable<T>> implements Iterator<ListNode<T>> { 00024 private ListNode<T> mHead = null; 00025 00033 public ListNodeIterator(ListNode<T> listNode) { 00034 this.mHead = listNode; 00035 } 00036 00037 @Override 00038 public boolean hasNext() { 00039 return this.mHead != null; 00040 } 00041 00042 @Override 00043 public ListNode<T> next() { 00044 ListNode<T> retVal = mHead; 00045 if (hasNext()) { 00046 mHead = mHead.getNext(); 00047 } 00048 return retVal; 00049 } 00050 00051 @Override 00052 public void remove() { 00053 throw new UnsupportedOperationException(); 00054 } 00055 00056 }