CSC153 2004S, Class 42: Designing List ADTs Admin: * About preregistration and the CS major * Fall * CSC223: Software Design (Stuck with Sam) * [223 or 362-Compilers] * CSC213: Operating Systems (CSC201 prereq) * [213 or 211-Architecture] * CSC301: Algorithms (MAT218, Combinatorics prereq) * * CSC205: Computational Linguistics (Linguistics prereq, but might be waived) * Algorithms for parsing sentences * The Google pagerank algorithm * And other similar stuff * All in Scheme! Yay! * Phy220: Electronics (Physics prereq, but might be waived if you had HS physics) * Build fun things in real space rather than virtual space * Good for Theatre geeks * Build circuits and stuff * Three projects * All of Tuesday and Thursday (more or less) * More math! (in 133 -> 215, Linear Algebra; in 215 -> 218, Combinatorics) * Spring * CSC201: C programming and Formal Methods * * CSC364: Computer Networks (CSC213 prereq) * Biocomputation special topics (CSC301 prereq) * CSC302: Programming languages (CSC301 prereq) * * Potentically HCI group independent * OS vs. Architecture and organization * OS: The program that manages everything on the computer (processes, filesystem, etc.) * Architecture: Assembly-language programming, design of hardware (registers, ALU, how addition works, pipelining, etc), * Questions on the exam? Ask good questions tomorrow so that our visitor is impressed * Cool convo today: Democracy and Catholicsm (Polysci is cool) * Cool talk tonight: The Truth (Comic book about Captain America as racist experiment) * Extremely cool talk at noon tomorrow: Humanities Informatics. How many pizzas should I order? 8-10 Overview: * What is a list, revisited? * What operations should lists provide? * What interesting variants are there? * Implementation Friday (arrays) and Monday (pairs) /Philosophies of Lists/ * Like Scheme lists (series of nodes/pairs): 4 * Sounds like an implementation rather than an ADT * Doubly-linked lists are a variant implementation * Circularly-linked lists are another variant implementation * Indexed collection: 2 * Sounds like an array * I didn't get around to it: 1 * Sounds wrong * Sam's theory: A list is a Collection you can iterate but may not have indexed access to * Generalized list: The order of iteration is up to the implementer * Ordered list: The client gets some explicit control over the order * Sorted list: The elements are iterated "in order" from smallest to largest * Hierarchy * Every ordered list is a generalized list * Every sorted list is a generalized list * Sorted lists are not ordered * Ordered lists are not sorted Observation: * We can generalize some of the Node methods by providing an abstract "position" What methods do your books provide for lists? * construct the empty list - GL * boolean isEmpty() - GL * addAtFront(Object newFront) - OL * addAtEnd(Object newFront) - OL * swapElement(Position here, Position there) - OL * remove(Position here) - GL * getNextItem() - GL * Assumption: implicit position * getAtIndex(int index) - Array * Object get(Position here) - GL * Position first() - GL * Position last() - GL * add(Object addme) - GL * addAfter(Position here, Object addme) - OL * addBefore(Position here, Object addme) - OL * boolean contains(Object value) - Set * Object replaceAt(Position here, Object replacement) - [returns replaced] * boolean isFirst(Position here) - GL * boolean isLast(Position here) - GL * Position prev(Position here) - GL * Position next(Position here) - GL * int length() - GL * void clear() - GL * Position find(Object findme) * remove(Object removeme) - GL [one or all copies of an object] The "instanceof" operation if (obj instanceof OrderedList) ((OrderedList) obj).addAtFront(whatever); else obj.add(whatever); Object.getclass() Design decision: Should we have implicit positions? /** * Add an element to the list. * * Postconditions: * All positions in the list are now invalidated. */ public void add(Object addme);