CIT 594 Fourth Quiz
Spring 2002, Dave Matuszek
Name __________________________________________
  1. (15 points) If you implemented a deque as a linked list,
    1. Would it be better to use a singly-linked list or a doubly-linked list?


    2. Why?


  2. (10 points) Suppose a stack of Objects is implemented as an array. When an Object is popped off the stack, should the corresponding array element be set to null? Why or why not?


  3. (20 points) Suppose s1, s2, and s3 have been declared to be of type Set. Write the Java instructions that will:

    1. Set s3 to the union of s1 and s2.


    2. Set s3 to the intersection of s1 and s2.


    3. Set s3 to the set difference s1 - s2.


    4. Test if Object obj is an element of the set s1.



  4. (5 points) What is a singleton?



  5. (30 points) Assuming that books is a Collection of some sort, write code to (1) get an iterator for books, and (2) use the iterator to print out every item in this collection.






  6. (10 points) What additional methods does a ListIterator have that an Iterator does not have?



  7. (10 points) All Collection implementations should have two constructors. Briefly describe these two constructors.