[Instructions] [Search] [Current] [Syllabus] [Links] [Handouts] [Project] [Outlines] [Labs] [More Labs] [Assignments] [Quizzes] [Exams] [Examples] [Book] [Tutorial] [API]
Back to Project Presentations. On to Traversing Trees.
Held Wednesday, November 24, 1999
Overview
Today, we continue our discussion of trees by considering the design of a tree interface and another application, expression trees.
Notes
Contents
Handouts
Summary
/**
* A simple way of looking a trees. Uses a cursor to support
* retrieval of information in the tree.
*
* @author Samuel A. Rebelsky
* @version 1.0 of November 1999
*/
public interface CursoredTree {
// +-----------+-----------------------------------------------
// | Modifiers |
// +-----------+
/**
* Set the value stored in the root of the tree.
* Pre: (none)
* Post: The root of the tree now contains newRoot.
* The tree is nonempty.
*/
public void setRoot(Object newRoot);
/**
* Set one of the children of the current node (given by the
* cursor). Children are numbered from 0 to numChildren-1.
* Pre: The cursor is at a known location.
* Post: The number of children is at least childNum-1.
* The childNum'th child contains newChild.
*/
public void setChild(Object newChild, int childNum);
/**
* Clear the subtree starting at the current node.
* Pre: The cursor is at a known location.
* Post: The cursor is at the parent of the current location
* (as long as the cursor was not at the root).
* There is now a "hole" where the subtree was.
*/
public void clear();
// +-----------------+-----------------------------------------
// | Cursor Movement |
// +-----------------+
/**
* Move the cursor to the root of the tree.
* Pre: (none)
* Post: The cursor is at the root of the tree.
*/
public void root();
/**
* Move the cursor up one level in the tree.
* Pre: The cursor is not at the root of the tree.
* Post: The cursor is at the parent of the current node.
*/
public void parent();
/**
* Move the cursor down to a child.
* Pre: The current node has at least childNum-1 children.
* Post: The cursor is on the node representing the specified child.
*/
public void child(int childNum);
// +-----------+-----------------------------------------------
// | Accessors |
// +-----------+
/**
* Get the value associated with the current node.
* Pre: There is a current node.
* Post: Returns the value associated with the current node.
*/
public Object getValue();
/**
* Get the number of children of the current node.
* Pre: There is a current node.
* Post: Returns the number of children associated with the current node.
*/
public int getNumChildren();
} // interface CursoredTree
+ -
/ \ / \
3 - * 6
/ \ / \
* 6 + 5
/ \ / \
4 5 3 4
Tuesday, 10 August 1999
Wednesday, 17 November 1999
Wednesday, 24 November 1999
Monday, 29 November 1999
Back to Project Discussion. On to Project Testing.
[Instructions] [Search] [Current] [Syllabus] [Links] [Handouts] [Project] [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.48.html
Source text last modified Mon Nov 29 09:14:53 1999.
This page generated on Mon Nov 29 09:42:33 1999 by Siteweaver. Validate this page's HTML.
Contact our webmaster at rebelsky@grinnell.edu