java - Implement iterator in Doubly-Linked List -
how implement class provides iterator iterating on doubly-linkedlist? should implemented private inner class within doubly-linkedlist class.
private class iterator<t> iterator(){ for(i = 0; list.size() > 20; i++){ system.out.println("using iterator approach (numbers > 20) list is: ") }
i don't know doubly-linkedlist class. may this.
public iterator<t> iterator() { return new iterator<t>() { node<t> node = head; @override public boolean hasnext() { return node != null; } @override public t next() { t value = node.value; node = node.next; return value; } }; }
Comments
Post a Comment