CMSC 341 Fall 1999 Project 2

Project 2

Assigned Monday, 20 September 1999
Due Monday, 04 October 1999


Background

The List ADT is a fundamental building block for other ADTs such as the Stack and Queue. In this project you will get a chance to implement a doubly-linked circular list to solve a problem.

Iterators provide an abstraction of the concept of position within a data structure and a mechanism for walking through a data structure one element at a time. In this project you will implement two iterators for the circular linked list.

This project will require a well thought out design before you can begin coding. Identifying problems, issues and their solutions at design time will save you an enormous amount of time compared to finding them at coding/testing/debugging time. You will be required to answer questions about the problems you discovered and the design decisions you made to solve those problems.


Description

Basically you will doing Exercise 3.15, part a (page 117) of the Weiss text as modified below. You are required to implement your list as a circular doubly-linked list (See sections 3.2.5 and 3.2.6 for descriptions of doubly-linked list and circular lists).

The solution will require that you implement two iterators for the list. One iterator (ListItr) runs from "beginning" to "end", referencing each data element of the list just once. The second iterator (CircListItr) runs around the circular list forever and never stops visiting data nodes (unless the list is empty). Please remember that you must provide good documentation as described in the "Project Organization" handout.

Here are your tasks:

  1. Read and understand the material on Lists in chapter 3.
  2. Understand the concept of the header node in the implementation of the List.
  3. Implement the List class as circular doubly-linked list. You may use any code found in the text. Source code from the text is available, but will most likely need to be modified. Dr. Anastasio has provided slightly modified code from the text in his public directory

    /afs/umbc.edu/users/a/n/anastasi/pub/CMSC-341

  4. Implement the ListItr class that iterates through the list just once. This iterator should support the common idiom: ListItr itr = theList.first (); for (; !itr.isPastEnd (); itr.advance () ) { Object x = itr.retrieve(); // process x }
  5. Implement the CircListItr class that continually iterates through the data elements in the list (unless the list is empty). This iterator should support the same idiom as above: CircListItr itr = theList.circFirst (); for (; !itr.isPastEnd(); itr.advance() { Object x = itr.retrieve (); // process x }
  6. Provide a main program to solve the Josephus problem described in Exercise 3.15 of the Weiss text. The main program takes two arguments Any errors on the command line (no argument, more than two arguments, argument not an integer, argument is an integer but value is inappropriate are to be reported to cerr and the program is to exit with a failure indication.
  7. Write a makefile. You can start with your makefile from Proj1 and modify it as needed.
  8. As with project 1, your code will need to handle exceptions. The text code throws BadIterator(). You should handle this situation and add any others you feel are appropriate.
  9. Answer the questions posed in 341-Fall99-proj2_questions.txt. Copy the file
    /afs/umbc.edu/users/a/n/anastasi/pub/CMSC-341/Proj2/341-Fall99-proj2_questions.txt
    
    to your own directory and edit it to provide your answers to the questions. Don't forget to submit the edited file; it counts 10% toward this project's grade.

Grading and Academic Integrity

Project grading is described in the Project Policy handout.

Your answers to 341-Fall99-proj2_questions.txt are worth 10% of your project grade.

Cheating in any form will not be tolerated. Please re-read the Project Policy handout for further details on honesty in doing projects for this course.

Remember, the due date is firm. Submittals made after midnight of the due date will not be accepted. Do not submit any files after that time.


Definition of the ADTs


List:
A List is a homogeneous sequence of Objects. Duplicates are allowed. Every List has infinite capacity, the number of elements it is capable of holding.

The operations listed below constitute a minimal ADT directed towards solving the Josephus problem in the text. You are free to add operations as you feel necessary, but all operations listed below must be implemented.

The operations allowed on a List are: