Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Resolves: part of issue #167 and part of issue #165
For #167, this PR handles the test infrastructure of linked list (i.e., we can now properly test all the linked list problem locally with the JSON representation of linked list as the input)
For #165, this PR moves
cppinclude
out ofleetcode
directory and move it into theinclude
directory.Main Techniques:
Runtime Complexity Analysis
Space Complexity Analysis
Testing
The testing for functions in
LinkedListRandom
class is done by usage. In this case, we invoke them in LC138 (see PR #168) implementation and make sure they are working properly.Performance
Performance Metrics from OJ Platform
Performance Improved Since Last Change
Implementation Notice
We use JSONCpp to parse the JSON input string. The version included in the repo has commit id: 2703c306a3168e15613d94e57fb8832138d9155d.
The implementation of
list2list
uses the idea of BFS when handling the objects within each level of JSON DOM and we uses the idea of LC138 (#168) to add the random pointers in the generated linked list.The implementation of
printList
uses the idea of LC206. Reverse Linked List's recursive approach.Implementation Tricks
To Do
We can replace
Node *head = new Node(0, nullptr, nullptr);
withstd::shared_ptr<Node> head(new Node(0, nullptr, nullptr));
but whetherstd::shared_ptr
is right one to use and the following error triggered atauto curr = head;
requires further investigation. In general, how we can incorporate smart pointers in the linked list implementation requires further study.To Learn
we use
std::unqiue_ptr
inconst std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
and we need to investigate further onunique_ptr
topic with related smart pointers.Questions
Language
const int rawJsonLength = static_cast<int>(rawJson.length());
usesstatic_cast
that castssize_t
(the unsigned int) intoint
, which is signed. Here, we usestatic_cast
to cast a larger arithmetic type to a smaller type. Withoutstatic_cast
, compiler often generates a warning for assignments of a larger arithmetic type to a smaller type. Once we do an explicit cast, the warning message is turned off. We can also usestatic_cast
to perform conversion that is not done by compiler automaticallyFailure Attempts