Thủ Thuật về Linked list edge cases Chi Tiết

Quý khách đang tìm kiếm từ khóa Linked list edge cases được Update vào lúc : 2022-01-03 15:05:16 . Với phương châm chia sẻ Kinh Nghiệm Hướng dẫn trong nội dung bài viết một cách Chi Tiết Mới Nhất. Nếu sau khi đọc tài liệu vẫn ko hiểu thì hoàn toàn có thể lại Comments ở cuối bài để Tác giả lý giải và hướng dẫn lại nha.

In this half of the assignment, you will implement the data structures you will be using on the second half.

Nội dung chính

    Part 1a: Write missing testsPart 1b: Implement DoubleLinkedListPart 1d: Implement ArrayDictionaryDeliverablesVideo liên quan

Part 1a: Write missing tests

Task: Modify and add in tests for the delete method.

In part 1a, you will practice writing some unit tests using jUnit.

Start by skimming through 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. Here are some suggestions on things you should test for:

Test the “happy case”: what happens you delete items from a list that has many items in it.Test edge cases: What happens if you try deleting items from the front or back of the list? What if the list is empty, or contains only one item?Test bad input: Does delete behave correctly if the user tries passing in invalid input? (E.g. do you throw the correct exception?)Test state updates: Does delete correctly update the size, for example?

See the JUnit tutorial if you need a reminder on how to write a unit test using JUnit.

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.

Part 1b: Implement DoubleLinkedList

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:

Discuss with your partner: what are the benefits and tradeoffs of using doubly-linked lists compared to singly-linked lists?

Your implementation should:

Be generic (e.g. you use generics to let the users store objects of any types in your list)Implement the IList interface.Be as asymptotically efficient as possible.Contain exactly as many node objects as there are items in the list. (If the user inserts 5 items, you should have 5 nodes in your list).

Warning: correctly implementing a doubly-linked list will require you to pay careful attention to edge cases. Some tips and suggestions:

    Think carefully about the end cases (front and back) and what should happen when the list is empty or nearly empty.

    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.

When implementing DoubleLinkedList, you will also need to implement an iterator for the class.

You should have studied iterators in CSE 143, but just in case you’ve forgotten, here is a quick reminder:

An iterator object is a kind of object that lets the client efficiently iterate over a data structure using a foreach loop.

Whenever we do something like:

for (String item : something)
// …etc…

…Java will internally convert that code into the following:

Iterator iter = something.iterator();
while (iter.hasNext())
String item =;
// …etc…

When you call for the first time, the iterator will return the first item in your list. If you call again, it’ll return the second item. Once the user calls enough time and encounters the last item in the list, calling once again should throw an NoSuchElementException.

The iter.hasNext() method will return true if calling will safely return a value, and false otherwise.

You can see an example of this expected behavior within your tests.

Notice that the iterator is behaving somewhat similar to a Scanner, except that it’s iterating over a data structure instead of a String or file.

In practice, iterators can also be used to safely modify the object they’re iterating over. We will not be implementing this functionality in this class: you should assume the client will never modify a data structure while they’re iterating over it.

Part 1d: Implement ArrayDictionary

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 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.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.

You may have noticed that the implementation we’ve described above does not feel very efficient it would take (mathcalO(n)) time to lookup a key/value pair.

This is true! We need dictionaries to do interesting things but also have not covered how to implement truly efficient dictionaries yet. We’ve compromised by having you implement a basic one for now.

You’ll implement more efficient dictionaries later this quarter, as a part of your second project.


The following deliverables are due on .

A single person from your partnership should submit the entire contents of your src thư mục using the submit tool.

Make sure that the src thư mục contains the following:

    The entire TestDoubleLinkedList class, which should contain the extra tests you added.Your completed DoubleLinkedList class.Your completed ArrayDictionary class.

Note: you do not need to modify the structure of your src thư mục or delete any files before submitting. The submitter will find the correct files and ignore any extraneous ones.


Chia sẻ


Review Linked list edge cases ?

Bạn vừa đọc Post Với Một số hướng dẫn một cách rõ ràng hơn về Clip Linked list edge cases tiên tiến và phát triển nhất

Share Link Down Linked list edge cases miễn phí

Hero đang tìm một số trong những Chia SẻLink Download Linked list edge cases Free.

Thảo Luận vướng mắc về Linked list edge cases

Nếu sau khi đọc nội dung bài viết Linked list edge cases vẫn chưa hiểu thì hoàn toàn có thể lại Comment ở cuối bài để Admin lý giải và hướng dẫn lại nha
#Linked #list #edge #cases