CSC297.Java 2003F, Class 21: List Cursors/Iterators Admin: * Have a great break! * Sam will try to write during break. * Homework for break: (1) Finish implementing YDLLItertaor (2) Implement some sorting algorithm on doubly-linked lists. Overview: * What methods did you come up with for iterators? * How will we implement those methods? Reminder: * Lists are collections of values that can be "iterated" * "Iterate" means to look at each value in the collection in turn * There are situations in which we iterate the list "in parallel" * Hence, we need separate "List Iterators" Basic Iterator Options: * Create a new iterator at the start of the list. * Advance the iterator to the next element. * Get the current value. * Retreat the iterator to the previous element (perhaps) * Delete the thing the iterator currently refers to and advance the iterator to the next element. * Advance the iterator to a particular value * Insert before * Insert after * Replace As an alternative to iterators, we can have fun higher-order procedures (map, fold, ...). The jwells operator, impelemented List jwells(List lst, BinaryProcedure binproc) { List result = new List(); Iterator left = lst.newIterator(); Iterator right = lst.newIterator(); right.advance(); while (right.isValid()) { result.addToEnd(binproc.applyTo(left.current(), right.current())); left.advance(); right.advance(); } return result; } // jwell(List, BinaryProcedure)