Courses‎ > ‎AP Computer Science 2‎ > ‎Konstantinovich‎ > ‎


posted Apr 5, 2017, 7:12 AM by Samuel Konstantinovich   [ updated Apr 5, 2017, 11:22 AM ]

Both  LinkedLists and ArrayLists can be used with the for each loop:

//SomeList can be any type that implements iterable<T>
SomeList<Integer> listThing = new SomeList<Integer>();
for( Integer i : listThing ){
  //do something with i

We need to make our MyLinkedLists implement Iterable.
This means we need to make our MyLinkedList have an Iterator function that returns an Iterator<Integer>

Our iterator should use the properties of a linked list to iterate in linear time. DO NOT use index based iteration, or you will get O(n^2) time to iterate through the linked list.

Final requirements for 09LinkedLists:
-Doubly Linked
-All the public methods posted yesterday
-Due Thurs after break