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

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -