[Instructions] [Search] [Current] [News] [Syllabus] [Glance] [Links] [Handouts] [Project] [Outlines] [Labs] [Assignments] [Quizzes] [Exams] [Examples] [EIJ] [JPDS] [Tutorial] [API]
Back to Linked Lists. On to Linked Lists, Concluded.
Held Wednesday, April 5, 2000
Overview
Today we continue to consider a node-based implementation of simple lists.
Notes
Contents
Summary
ConsCells that are essential
to Scheme-like lists.
/**
* An implementation of simple list usings linked
* nodes. Each node contains a link to the next
* element of the list. This version still lacks
* delete methods.
*
* @author Samuel A. Rebelsky
* @author The Students of CSC152 2000S
* @version 0.1 of April 2000
*/
public class SimpleLinkedList
implements SimpleList
{
// +--------+-----------------------------------------
// | Fields |
// +--------+
/**
* The first element of the list. All other elements are
* reachable from this element. This element is set to null
* if the list is empty.
*/
protected ConsCell front;
/**
* The last element of the list. Useful when we want to
* quickly add to the end of the list.
*/
protected ConsCell back;
/**
* The current element of the list. Used for iteration.
*/
protected ConsCell current;
// +--------------+-----------------------------------
// | Constructors |
// +--------------+
/**
* Create a new empty list.
*/
public SimpleLinkedList() {
front = null;
back = null;
current = null;
}
// +----------------------+---------------------------
// | Iteration Operations |
// +----------------------+
public Object getCurrent() {
return current.getContents();
} // getCurrent()
public void advanceCurrent() {
current = current.cdr();
}
public void reset() {
current = front;
}
// +-----------+----------=---------------------------
// | Modifiers |
// +-----------+
// Needs work!
public void add(Object something) {
// Create a new cell to hold the thing.
ConsCell newCell = new ConsCell(something, null);
// Put it after the last element
back.setNext(newCell);
// Make it the new last element.
back = newCell;
} // add(Object)
} // class SimpleLinkedList
add?
addAfterCurrent?
delete?
retreatCurrent?
Tuesday, 18 January 2000
Wednesday, 5 April 2000
Back to Linked Lists. On to Linked Lists, Concluded.
[Instructions] [Search] [Current] [News] [Syllabus] [Glance] [Links] [Handouts] [Project] [Outlines] [Labs] [Assignments] [Quizzes] [Exams] [Examples] [EIJ] [JPDS] [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/2000S/Outlines/outline.35.html
Source text last modified Fri Apr 7 09:19:01 2000.
This page generated on Fri Apr 7 09:55:16 2000 by Siteweaver. Validate this page's HTML.
Contact our webmaster at rebelsky@grinnell.edu