| CS 261 | University of Puget Sound | Spring, 2020 |
|
Computer Science II
|
||
|
Abstract Data Types and their Implementations,
Some Basic Algorithms,
Object-oriented Problem Solving, and Efficiency |
||
Warning:
This course is under development.
Although the basic structure of this course is largely established,
nothing on this Web site should be considered official or even possibly
correct.
DO NOT MAKE PLANS BASED ON THE CONTENTS OF THIS SITE UNTIL JANUARY, 2020.
This lab applies ideas of box-and-pointer representations and provides practice using lists with Java.
The reading for this lab describes box-and-pointer diagrams as a graphical model for lists.
Draw box-and-pointer diagrams for each of the following lists:
((x) y z) (x (y z)) ((a) b (c ()))
Copy classes
ListNode.java and
SimpleList.java
to Eclipse and run SimpleList. This program will serve as the
basis for the remaining steps of this lab. Be sure to ask about any
sections you do not understand.
Add a function second to this program that returns the data stored in the second element in a list (if present) or an empty string if the list is null or has only one element.
In this exercise and the subsequent ones,
Add a function count which counts how many times a specified item appears on a list. count should have two parameters: the list (of type listNode) and the desired item (of type int) for the search. Of course, if the item is not on the list, the function should return a count 0. In writing this code, you should use an iterative approach.
Be sure to test your code to see if it works for a null list and that it works for lists of various lengths.
Add a function last which returns the last item on the
list. (If the list is null, the function should return
the empty string.)
Be sure to test your function to see if it works for a null list, for a list with only one element, and for a list which has more than one element.
Add a function getIndex that finds the first index of the
integer number in a list.
The function should use as parameters a pointer to the list and a
number to look for. It should produce index,
an integer.
Test cases should include circumstances in which:
number does not appear on the list.
|
created 4 May 2000 by Henry m. Walker revised 4 August 2011 by David Cowden and Dilan Ustek revised 17 April 2012 by by Henry M. Walker> reorganized and expanded 9 February 2014 by by Henry M. Walker readings added 19 September 2014 by Henry M. Walker functions clarified 22 April 2018 by Henry M. Walker converted from C to Java 20-26 January 2020 by Henry M. Walker |
|
| For more information, please contact Henry M. Walker at walker@cs.grinnell.edu. |