| CIT594 Midterm Exam Spring 2009 |
Name_________________________________________ |
Please keep all your answers short and to the point. Do not provide extra information that was not asked for.
Stack class
typically has one more method than it would if it were implemented
as a linked list. What is that operation?
Collection
interface? (Cross out the ones that are not.)boolean add(E o)boolean addAll(Collection<? extends E> c)void add(int index, E element)Iterator<E> iterator()Set<E> toSet(Collection<E>)Collection interface:
add
contains
containsAll
iterator
equals
Set method that implements it.
addAll
|
(-> union) | union |
contains
|
(-> member) | intersection |
containsAll
|
(-> subset) | difference |
removeAll
|
(-> difference) | member |
retainAll
|
(-> intersection) | subset |
class MyList { int value; MyList next; ...}
MyList(int value, MyList next).
Write a recursive method int last() to put in this class; the
method should return the last value in the list. You may assume the list is not empty.int last()
method described in the previous question.LinkedList or an ArrayList, and why?
|
![]() |
number:
int n = number;
int count = 0;
while (n > 0) {
n = n / 10;
count++;
}How long (in Big-O terms) does this method take? Why?ListIterator
but not in an Iterator?LinkedList?Iterator method throw a
ConcurrentModificationException?<small
integer>, where a "small integer" is a number in the range -99 to
99.<foo> ::= { [ a ] b } { c [ d ] },
where the brackets and braces are BNF metasymbols. Circle each of
the following strings that are <foo>s, and cross out
the ones that are not.a b c da b ca a b d da b b c d c c dd
Vehicle objects into a
HashSet, the Vehicle class must override both
hashCode() and equals(Object). Vehicle objects into a
TreeSet (which is a SortedSet), the Vehicle
class must override both
equals(Object) and compareTo(T) (OR compare(T, T)). new
String[10][].