

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
In this document, students are provided with instructions and files for creating two iterators (forward iterator and find iterator) for a singly linked list in java. The objectives of the lab include gaining experience using the interface feature, implementing a traversal iterator, and implementing a find iterator. Students are encouraged to write test cases before writing methods and are required to implement the constructor, get(), next(), isvalid(), and delete() methods for each iterator.
Typology: Lab Reports
1 / 3
This page cannot be seen from the preview
Don't miss anything!


Iterators 1 GIVEN FILES
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 iterator-lab directory. Do a git pull in your repository to download it. Inside you will find the following files:
compile Compiles everything. compile-list Compiles List files. compile-fwd Compiles Forward Iterator tests. compile-find Compiles Find Iterator tests. tests Tests everything. test-list Tests List files. 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, assuming it is a valid node. It does not advance the cursor after returning a node! If there is no current element, return null. It does advance the cursor, though, before returning any data, if the deleted flag is set.
void next() Advance the iterator’s cursor to the next node that does not have the deleted flag set. If the iterator is currently invalid, do nothing.
boolean isValid() Return true if the iterator still has data. If the deleted flag is set in the current cursor, the iterator should advance itself first.
void delete() We’ve added this one to the usual mix. It will delete the current element from the original list, set the cursor’s deleted flag, and advance the iterator’s cursor. Do nothing if the cursor is invalid. Other iterators that are pointing to a deleted element don’t need to do anything special, as long as they honor the deleted flag.
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.