Due Wed, Jan 10 at 11:30pm
In this half of the assignment, you will implement the data structures you will be using on the second half.
Task: Modify TestDoubleLinkedList.java
and add in
tests for the delete
method.
In part 1a, you will practice writing some unit tests using jUnit.
Start by skimming through TestDoubleLinkedList.java
and
familiarize yourself with the tests we have given you. Since this is the
first assignment, we've given you most of the tests you need, except for
a few. Can you see what tests are missing?
There are no tests for the DoubleLinkedList.delete(...)
method! Add new methods testing your delete method.
You may find the following documents from the resources page to be particularly useful:
You may be tempted to do this step last and jump straight into writing code. This is a bad habit: that kind of cowboy attitude doesn't really scale to larger projects.
Task: complete the DoubleLinkedList
class.
A doubly-linked list is a similar to the singly-linked lists you studied in CSE 143 except in two crucial ways: your nodes now have pointers to both the previous and next nodes, and your linked list class has now have pointers to both the front and back of your sequence of list node objects.
Visually, the singly linked lists you studied in CSE 143 look like this:
Doubly-linked lists containing the same data will look like this:
Your implementation should:
IList
interface.Warning: correctly implementing a doubly-linked list will require you to pay careful attention to edge cases. Some tips and suggestions:
Write pseudocode for your methods before writing code. Avoid immediately thinking in terms of listnode manipulation – instead, come up with a high-level plan and write helper methods that abstract your node manipulations. Then, flesh out how each helper method will work.
Or to put it another way, figure out how to refactor your code before you start writing it. Your code will be significantly less buggy that way.
Task: complete the ArrayDictionary
class.
Your ArrayDictionary
class will internally keep track of
its key-value pairs by using an array containing Pair
objects.
Dictionary<String, Integer> foo = new ArrayDictionary<>();
foo.put("a", 11);
foo.put("b", 22);
foo.put("c", 33);
Your internal array should look like the following:
Now, suppose the user inserted a few more keys:
foo.put("d", 44);
foo.remove("b");
foo.put("a", 55);
Your internal array should now look like the below. Notice that we've updated the old key-value pair for "a" to store the new value. We've also removed the key-value pair for "b".
This means you will need to scan through the internal array when retrieving, inserting, or deleting elements. If your array is full and the user inserts a new key, create a new array double the size of the old one and copy over the old elements.
Once completed, the design and logic of your
ArrayDictionary
should feel very similar to the
ArrayIntList
objects you previously studied in CSE 143.
If you finished early, you may want to start on the writeup portion of this project (see the project 1, part 2 spec for more details). While the writeup is not due this week, it contains questions that focus exclusively on material from part 1.
You may find working on the writeup to be a good way of helping you determine whether your data structures are designed soundly.
The following deliverables are due on Wed, Jan 10 at 11:30pm.
A single person from your partnership should
submit the entire contents of your src
folder
as a zip file
on Canvas.
Please follow the above instructions EXACTLY. Do not
remove, rearrange, or rename any files or folders: just zip your src
folder. (This means you will be submitting a lot of instructor-provided code along
with your files. This is fine.)
Before submitting, be sure to double-check that:
TestDoubleLinkedList
,
DoubleLinkedList
, and ArrayDictionary
classes
which all behave as expected.