[Instructions] [Search] [Current] [News] [Syllabus] [Glance] [Links] [Handouts] [Project] [Outlines] [Labs] [Assignments] [Quizzes] [Exams] [Examples] [EIJ] [JPDS] [Tutorial] [API]
Held Tuesday, April 11, 2000
Overview
Today we experiment with two implementations of stacks. Similar implementations will be appropriate for queues (although not for priority queues).
Notes
http://www.faqs.org/rfcs/rfc2795.html
Contents
Summary
In order to do this lab, you will need the following files.
Node.java
Linear.java
Stack.java
NodeBasedStack.java
StackTester.java
NBSTester.java
ArrayBased.java
NBSTester.java
SimpleInput.java
SimpleOutput.java
mkdir command.
You need not turn in answers to these questions. However, you should be prepared to answer them in class and on exams. Feel free to discuss the questions with your colleagues. We'll reflect on them after a few minutes of discussion, perhaps ten minutes after the start of lab.
StackTester and
NBSTester classes? What is the advantage of this
architecture?
StackTester?
NBSTester?
Design a simple test plan that you might use to test an implementation of stacks. You might consider what the implementation should do when the same element is added multiple times, when the last element is deleted, and so on and so forth. Summarize your plan and the expected output.
We'll do this as a class.
NBSTester). Does the
NodeBasedStack class seem to work the way
you expect?
It might be easier to test the class if you could see the stack
being built. Write a toString method that generates
a human-readable representation of the contents of the stack. Here's
a possible strategy:
create tmp, a reference to the top of the stack create a result string while tmp does not refer to the top of the stack add the contents of tmp to the result string set tmp to the next element
Once you've written this method, make sure to test it (perhaps by running your test plan).
Note that this is a puzzle about object-oriented design, and not necessarily about stacks.
Both add and get in the
Linear class have a precondition having to do with the
number of elements in the structure. It might be helpful if the methods
threw an exception in cases in which the structure has no elements
(get) or no room (add).
Linear.java so that
it's clear that get throws an exception.
Linear.java, Stack.java,
and StackTester.java.
Does everything continue to work successfully?
Linear.java so that
it's clear that add throws an exception.
Linear.java, Stack.java,
and StackTester.java.
Does everything continue to work successfully?
NodeBasedStack so that it throws exceptions
in add and get.
Stack so that it throws exceptions in
get.
ArrayBasedStack and ensure that it
compiles.
ABSTester class that can be used to test
array-based stacks. You may want to refer to
NBSTester for assistance.
isEmpty method
in ArrayBasedSTack.
add method in ArrayBasedStack.
This method should add the object at the end of the array and update the
size.
get implemented
to test the method because I've already implemented toString.
peek method in ArrayBasedStack.
This method should return the ``last'' element in the array.
get method in ArrayBasedStack.
This method should decrease the size of the stack and return the old
last element.
Tuesday, 18 January 2000
Tuesday, 11 April 2000
Back to Introduction to Linear Structures. On to Automated Problem Solving with Linear Structures.
[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.38.html
Source text last modified Tue Apr 11 09:39:25 2000.
This page generated on Tue Apr 11 09:41:18 2000 by Siteweaver. Validate this page's HTML.
Contact our webmaster at rebelsky@grinnell.edu