

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


Iterators 1 GIVEN FILES
Rev : 470
In this lab you will create two iterators for a singly linked list.
You are given 6 files for this lab. They are in the cs331/Iterators directory. Do an svn update in the cs331 directory to download it. Inside you will find the following files:
compile Compiles everything. compile-list Compiles everything. compile-fwd Compiles Forward Iterator tests. compile-find Compiles Find Iterator tests. tests Tests everything. test-list Tests everything. test-fwd Tests Forward Iterator. test-find Tests Find Iterator.
Iterators 2 YOUR WORK
2 Your Work
For both of these classes, you must implement the methods listed below, and you must use the List class we’ve provided. You are encouraged to write your test cases before you write your methods; at least start them. You may well realize you need to add more tests as you are coding. In this lab you will write two iterators. As discussed in lecture, iterators have four basic methods. We will implement five.
constructor we need to create them, after all!
E get() Return the current element. It does not advance the cursor! If there is no current element, return null.
void next() Advance the iterator’s cursor. If the iterator is currently invalid, do nothing.
boolean isValid() Return true if the iterator still has data.
void delete() We’ve added this one to the usual mix. It will delete the current element from the original list, and advance the iterator’s cursor. Do nothing if the cursor is invalid.
The behavior of other iterators after a delete has occurred is undefined. You can do anything you like other than throw an exception. The official tests will not test this condition.
You will need a local variable, at least, for the iterator’s cursor.
Once created, it will allow us to iterate over the list. For testing, you will want to test several things. Remember that in CS there are three numbers: 0, 1, and n.