CSC153 2004S, Class 48: Priority Queues Admin * Lots to cover today; avoid distractions * Class may be cancelled on Wednesday; Homework still due * Questions on HW7? * Why a circularly-linked doubly-linked list? Because you learn by building one. * How do I write all of the stuff to a file? * Method one: * Write a toString method for tasks * Write a constructor for tasks that takes a string as a parameter * The rest is obvious * Method two: Serialize * Make your class implement Serializable * Write using an ObjectOutputStream (built from a FileOutputStream) * Read using an ObjectInputStream (built from a FileInputStream) * See Person.java, CerealOut.java, CerealIn.java * You can probably make TaskList (and everything else) serializable and all will be hunkydory. * How does writeObject work? Sam's guess * First, verify that the object is serialable * Next, determine the fields of the object (using getClass and getFields) * Write the type of the object * For each field, get the value and write it to the file * When you have an object field, write a "placeholder" and put the object on a queue (or stack) of other objects that must be written * Recursively write anything in the queue/stack * How does readObject work? Sam's guess * The opposite * What are the odds we'll get a test or some homework back? 100% * What are the odds it will be graded when we get it back? 100% * What are the odds it will be before the end of the semester? 100% * What are the odds it will be Wednesday? 25% Overview: * Priority queue basics * Simple implementations * Detour: Binary trees * Heaps * An alternate implementation of heaps