CSC153 2004S, Class 46: Implementing Lists with Nodes, Revisited Admin: * DingDongs * Picnic * No homework yet. Sorry Overview: * Linked lists: Implementing lists with nodes. * Implementing basic methods * Implementing ordered methods * Cool tricks Step one: Look at ListNode.java Step two: Look at LinkedList.java Detour: * Classes extend other classes * Classes also extend abstract classes (because every abstract class is a class) * Classes implement interfaces (multiple "inheritance" permitted) * Interfaces extend other interfaces (multiple "inheritance" permitted) Detour: * Four levels of protection Move from actual coding to generic coding * In doubly-linked lists, it makes sense to keep track of the last element as well as the first. * The previous operation is much easier to implement return ((DoublyLinkedNode) pos).prev; * Deletion is somewhat easier to implement (and certainly more efficient) node.prev.next = node.next; node.next.prev = node.prev; node.next = null; node.prev = null; * What are the problems with this "simple" code? * Deleting the first and last elements requires special cases * Traditional clever trick: Circularly-linked lists * One node that is never deleted (comes after the last node and before the first) * Next of last is first, prev of first is last.