[Instructions] [Search] [Current] [Syllabus] [Links] [Handouts] [Outlines] [Labs] [More Labs] [Assignments] [Quizzes] [Exams] [Examples] [Book] [Tutorial] [API]
Back to Implementations of Lists. On to Project Discussion.
Held Thursday, October 28, 1999
Overview
Notes
Contents
Handouts
Summary
// +--------+--------------------------------------------------
// | Fields |
// +--------+
public class SimpleDynamicList {
/**
* The length of the list. It's easier to keep track of this
* than to recompute it each time that it's needed.
*/
int length;
/**
* The elements of the list. When the list is empty, this is
* null. Otherwise, it is the cons cell at the front of the list.
*/
ConsCell front;
/**
* The current element of the list. Used to support iteration.
*/
ConsCell current;
// ...
// +---------+-------------------------------------------------
// | Methods |
// +---------+
/**
* Determine whether there is space available. See the
* interface for preconditions and postconditions.
*/
public boolean spaceAvailable() {
return true;
} // spaceAvailable()
/**
* Add an element to the list. See the interface for
* preconditions and postconditions.
*/
public void add(Object element) {
// It's easiest to add the element at the front of the
// list. We can do so by creating a new cons cell and
// putting it at the front of the list.
this.front = new ConsCell(element, this.front);
} // add(Object)
/**
* Get the next element. See the interface for preconditions
* and postconditions.
*/
public Object nextElement()
throws Exception
{
if (current == null) {
throw new Exception("No more elements!");
}
// Extract the element at the head of the current sublist.
Object returnMe = current.head();
// Advance the current sublist.
current = current.tail;
// That's it, we're done.
return returnMe;
} // nextElement
// ...
} // class SimpleDynamicList
Tuesday, 10 August 1999
Wednesday, 27 October 1999
Thursday, 28 October 999
Monday, 1 November 1999
Monday
Back to Implementations of Lists. On to Project Discussion.
[Instructions] [Search] [Current] [Syllabus] [Links] [Handouts] [Outlines] [Labs] [More Labs] [Assignments] [Quizzes] [Exams] [Examples] [Book] [Tutorial] [API]
Disclaimer Often, these pages were created "on the fly" with little, if any, proofreading. Any or all of the information on the pages may be incorrect. Please contact me if you notice errors.
This page may be found at http://www.math.grin.edu/~rebelsky/Courses/CS152/99F/Outlines/outline.33.html
Source text last modified Mon Nov 1 08:20:29 1999.
This page generated on Mon Nov 1 08:32:04 1999 by Siteweaver. Validate this page's HTML.
Contact our webmaster at rebelsky@grinnell.edu