SUNY Geneseo Department of Computer Science
{Date}
CSci 141, Spring 2005
Prof. Doug Baldwin
First hour exam is this Friday (Mar. 4)
Sections 11.1 and 11.2
Lists
List has subparts, items
Subparts called "elements"
Operations on lists
Elements are linked or connected to next
Every element appears on path once
Element and its link = "node"
"Head" refers to first element, "tail" to last
Recursive definition of list
Constructor() - initialize an empty list
Constructor( head, tail ) - initialize a list with element "head" and smaller list "tail"
getFirst() - return head element
getRest() - return smaller list
isEmpty() - return true if list is empty
Member variables
class List {
private Object head;
private List tail;
...
length() - return number of elements in list
// In class List or one of its subclasses
int length()
if this.isEmpty()
return 0
else
return this.getRest().length() + 1
(After test)
Implementing Lists
Read Sections 11.3 and 11.4