CSC153 Class 44: More List ADT Design Overview * Comparing list design * Deletion and iteration * Implementing lists with arrays Notes * Are there any questions on the exam? * Reminder: Fun movie on Monday * Admittees visiting (lots and lots of them) Why should these admittees come here? * "Sam's great" * Professors are fun and interesting and make sarcastic jokes and care and bring their kids to class. * Plans, an aspect of the cool Grinnell culture (and self governance) * Relaxed intellectual atmosphere * Lots of interesting traditions + National pipe cleaner day + Titular Head - Student film-making contest + Plans: Fun online interaction board + Self governance: Students determine rules of behavior + Grinnell Relays + Alice * College vs. Graduate schools + No teaching by graduate students + Faculty who make teaching their primary responsibility + Opportunities to do research with faculty * Careful language: "First year" vs. "freshman", "Second year" vs. "sophomore" * Lots of chances to interact with students from multiple countries (and to go to multiple countries) + 10% of campus is non-American + 60% of students study abroad * We teach Scheme in the first course. Scheme is a really cool language at Grinnell. Elsewhere it's evil. * Grinnell students never form opinions about things (like Scheme) without encountering them first. ---------------------------------------- Lists Collections that you can step through Vs. Collections you may not step through Primary operation: Does this set contain this value Vs. Indexed Collections Accessing a specific element by number ---------------------------------------- Official sun.Java design decision: Iterators (Cursors) provide a next() procedure that simultaneously returns the next() objectr and advances the iterator. vs. Official CSC153 design decision advance() advances without returning getValue() gets without advancing How to print a list: Java while (thingy.hasNext()) out.println(thingy.next()); Ours while (!thingy.atEnd()) { out.println(thingy.getValue()); thingy.advance(); } Whoops ... doesn't print the last element do { out.println(thingy.getValue()); thingy.advance(); } while (!thingy.atEnd()); Crash and burn for empty lists (bad). Still doesn't print last element! while (!thingy.atEnd()) { out.println(thingy.getValue()); thingy.advance(); } out.println(thingy.getValue()); Prints the last element Crashes and burns for empty list But we don't have cursors for empty lists. ---------------------------------------- What happens to a cursor if you delete an element from the list? Sam says: "All cursors are invalid." Students say: "Blech". Arjun investigated what Sun Java does. delete "might" throw a "ConcurrentModificationException" Sun says the same thing as Sam.