Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Issue] Resolve part of 167 & 165 #169

Merged
merged 10 commits into from
Oct 29, 2019
Merged

[Issue] Resolve part of 167 & 165 #169

merged 10 commits into from
Oct 29, 2019

Conversation

xxks-kkk
Copy link
Owner

@xxks-kkk xxks-kkk commented Oct 29, 2019

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 of leetcode directory and move it into the include 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); with std::shared_ptr<Node> head(new Node(0, nullptr, nullptr)); but whether std::shared_ptr is right one to use and the following error triggered at auto 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 in const std::unique_ptr<Json::CharReader> reader(builder.newCharReader()); and we need to investigate further on unique_ptr topic with related smart pointers.

Questions

Language

  • const int rawJsonLength = static_cast<int>(rawJson.length()); uses static_cast that casts size_t (the unsigned int) into int, which is signed. Here, we use static_cast to cast a larger arithmetic type to a smaller type. Without static_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 use static_cast to perform conversion that is not done by compiler automatically
void* p = &d; // ok: address of any nonconst object can be stored in a void* 
double *dp = static_cast<double*>(p); // // ok: converts void* back to the original pointer type

Failure Attempts

@xxks-kkk xxks-kkk added C++ good C++ usage and practice; C++ usage note infrastructure Code infrastucture should be reusued in the future implementation (e.g., better test case org) labels Oct 29, 2019
@xxks-kkk xxks-kkk added this to the 1.0 milestone Oct 29, 2019
@xxks-kkk xxks-kkk changed the title [Issue] 167 [Issue] Resolve part of 167 & 165 Oct 29, 2019
@xxks-kkk xxks-kkk added the tolearn New knowledge can be learnt from label Oct 29, 2019
@xxks-kkk xxks-kkk merged commit 1d852f9 into master Oct 29, 2019
@xxks-kkk xxks-kkk deleted the issue-167 branch October 29, 2019 19:24
@xxks-kkk xxks-kkk added the todo Some leftover need to be done label Oct 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C++ good C++ usage and practice; C++ usage note infrastructure Code infrastucture should be reusued in the future implementation (e.g., better test case org) todo Some leftover need to be done tolearn New knowledge can be learnt from
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant