SUNY Geneseo Department of Computer Science
{Date}
CSci 141, Fall 2003
Prof. Doug Baldwin
Hand out Lab 9
Step-count for Lab 8
findLargest( n )
--> if n <= 0
return A[0]
else if ....
Maintain a list of things to do
List toDo = new List()
for each task to do today
toDo = new List( task, toDo )
while ! toDo.isEmpty()
toDo.first().do()
[ do whatever it takes to complete first task ]
toDo = toDo.rest()
Fill in details of loop as mini-assignment (done above)
List operations
"Big Three" operations
(Variations on these definitions are common)
Design a DataList subclass of List that provides these operations
class DataList extends List {
DataList insert( Object x ) {
return new DataList( x, this )
}
boolean search( Object x ) {
if ( ! this.isEmpty() ) {
if ( this.first() == x ) {
return true
}
else {
this = this.rest()
this.search( x )
}
}
else {
return false;
}
}
DataList delete ( Object x ) {
...
}
}
("search" has a few things that still need to be cleaned up Friday)
Client examples
DataList d = new DataList()
d = d.insert( "Hello" )
What is "Object?"