SUNY Geneseo Department of Computer Science
{Date}
CSci 141, Fall 2003
Prof. Doug Baldwin
Proofs and derivations for lab 9 should be standard induction, recurrence analyses
EveryOtherItem
class DataList extends List {
DataList insert( Object x ) {
return new DataList( x, this )
}
boolean search( Object x ) {
if ( ! this.isEmpty() ) {
if ( this.first().equals(x) ) {
return true
}
else {
return this.rest().search( x )
}
}
else {
return false;
}
}
DataList delete ( Object x ) {
// Postcondition: Result contains no
// occurrences of x
if ( this.isEmpty() ) {
return this
}
else {
if ( this.first().equals(x) )
return this.rest().delete( x )
else {
return new DataList( this.first(), this.rest().delete( x ) )
}
}
}
}
Comments on search
Efficiency -- how many primitve List messages do these send? (correlated with execution time)
Mini-assignment: work out number of primitive messages for delete