INFS 590 Program Design and Data Structures
Fall 1999


INFS 590 Programming Assignment 5 -- Extra Credit
due Thursday, December 9
*** No late submissions accepted for this assignment ***


Educational Goals: Understanding the Midterm exam.

This programming assignment is extra credit ... it is completely optional, and there will be no penalty if you do not turn it in.

Program Requirements

Question 7 on the midterm exam was to add two methods to a linked list class. The question was:

Following is part of an implementation for a List class. Use it to write bodies for the two methods that have specifications but not bodies (InsertAtEnd() and FindLastOccurrence()). The method bodies must (1) satisfy the pre- and post-conditions, and (2) be consistent with the constructor and Insert methods provided. Make any assumptions you need about other methods in List, but be sure to tell me those assumptions. Write your methods on the next page.

For this assignment, you should type in the List class that was shown on the exam, get the Node class from the textbook, and then implement the two methods InsertAtEnd() and FindLastOccurrence(). You also need to add the standard iterator methods First(), IsInList(), Advance(), and GetCur(). (GetCur() should return the current element.)

Finally, you need to add a main method to demonstrate your program. Your main must follow the following algorithm:

Define and construct a list (l1)
If your Node class is inside your List class, call the main method in Node
l1.Insert(1);
l1.Insert(2);
l1.Insert(3);
l1.Insert(4);
l1.Insert(5);
l1.InsertAtEnd(2);
l1.InsertAtEnd(4);
l1.InsertAtEnd(6);
l1.InsertAtEnd(4);
l1.InsertAtEnd(7);

for (l1.First(); l1.IsInList(); l1.Advance())
    print (l1.GetCur());

l1.FindLastOccurrence(2);
print (l1.GetCur());
l1.Advance();
print (l1.GetCur());

l1.FindLastOccurrence(4);
print (l1.GetCur());
l1.Advance();
print (l1.GetCur());

for (l1.FindLastOccurrence(2); l1.IsInList(); l1.Advance())
    print (l1.GetCur());

Submission and Input Specifications

As before, your program will be compiled and run automatically. Therefore, it is very important that your program use the naming convention from the previous programs. Notice that there are no input requirements. However, your main method must implement exactly the algorithm given above, without any additional output.

Grading Criteria

Your program will be graded on the following factors:

Jeff Offutt
Nov 11 1999