-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
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
feat: Add sorting/count_inversions.cpp #1425
Conversation
Counts the number of inversions in a list using merge sort. The number of Inversions in a list is the measure of the list's proximity to being sorted in ascending/increasing order.
I had previously closed this PR. @kvedala had asked to implement using templates which I did not know then. I have, since then, learned about STL library and templates from YT and formatted the code to the best of my ability. It has passed all tests. Let me know if there are any more changes you'd like to see. |
- fixed template error on line 156 - an added test case for character array - an added test case for list type double
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall the algorithm looks good; Very well documented. Keep it up!
Co-authored-by: Taj <tjgurwara99@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please enable GitHub Actions in your repository of this fork in this link: https://github.com/rakshitraj/C-Plus-Plus/actions
Co-authored-by: Taj <tjgurwara99@users.noreply.github.com>
Co-authored-by: David Leal <halfpacho@gmail.com>
b51af5e
to
78ecce2
Compare
78ecce2
to
81560e8
Compare
and doxygen formatiing
Done. Please mark this. It is being counted as pending action. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remember it doesn't need to be uint64_t
. It can also be uint32_t
, uint16_t
or even uint8_t
, (for non-negative values) depends on the variable and the required size. 🙂
Co-authored-by: David Leal <halfpacho@gmail.com>
Co-authored-by: David Leal <halfpacho@gmail.com>
Co-authored-by: David Leal <halfpacho@gmail.com>
Co-authored-by: David Leal <halfpacho@gmail.com>
fcf41c4
to
0f9a744
Compare
Co-authored-by: David Leal <halfpacho@gmail.com>
Co-authored-by: David Leal <halfpacho@gmail.com>
Co-authored-by: David Leal <halfpacho@gmail.com>
e81cc08
to
b352ced
Compare
Update count_inversions.cpp
Co-authored-by: David Leal <halfpacho@gmail.com>
Co-authored-by: David Leal <halfpacho@gmail.com>
e8a31ae
to
f941a09
Compare
Co-authored-by: David Leal <halfpacho@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for your efforts and contribution, @rakshitraj! 🎉👍
@kvedala @ayaankhan98 please review. Thanks. 🙂 |
// static void body() { | ||
// // Input your own sequence |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but I'm not sure if we want this whole block commented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's all the same, I'd like the commented block to remain as a reference for any beginner who is reviewing the code. Count inversion is one of the most asked questions on Algo assignments, so most people to refer to this will likely be students.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your pull request!🤩
Co-authored-by: John Law <johnlaw.po@gmail.com>
Will merge this PR. If there are any errors, please make a new PR to propose a fix. Thank you. 🙂 |
* Create count_inversions.cpp Counts the number of inversions in a list using merge sort. The number of Inversions in a list is the measure of the list's proximity to being sorted in ascending/increasing order. * Update count_inversions.cpp - fixed template error on line 156 - an added test case for character array - an added test case for list type double * Update sorting/count_inversions.cpp Co-authored-by: Taj <tjgurwara99@users.noreply.github.com> * Update sorting/count_inversions.cpp Co-authored-by: Taj <tjgurwara99@users.noreply.github.com> * Update sorting/count_inversions.cpp Co-authored-by: David Leal <halfpacho@gmail.com> * updating DIRECTORY.md * clang-format and clang-tidy fixes for b51af5e * using `uint64_t` from cstdint header and doxygen formatiing * clang-format and clang-tidy fixes for 047578b * Update count_inversions.cpp * added comments on imports * clang-format and clang-tidy fixes for 2f65017 * Update sorting/count_inversions.cpp Co-authored-by: David Leal <halfpacho@gmail.com> * Update sorting/count_inversions.cpp Co-authored-by: David Leal <halfpacho@gmail.com> * Update sorting/count_inversions.cpp Co-authored-by: David Leal <halfpacho@gmail.com> * Update sorting/count_inversions.cpp Co-authored-by: David Leal <halfpacho@gmail.com> * Update count_inversions.cpp * clang-format and clang-tidy fixes for 5d5cc53 * Update sorting/count_inversions.cpp Co-authored-by: David Leal <halfpacho@gmail.com> * Update sorting/count_inversions.cpp Co-authored-by: David Leal <halfpacho@gmail.com> * Update sorting/count_inversions.cpp Co-authored-by: David Leal <halfpacho@gmail.com> * Update sorting/count_inversions.cpp Co-authored-by: David Leal <halfpacho@gmail.com> * Update sorting/count_inversions.cpp Co-authored-by: David Leal <halfpacho@gmail.com> * Update sorting/count_inversions.cpp Co-authored-by: David Leal <halfpacho@gmail.com> * Update sorting/count_inversions.cpp Co-authored-by: David Leal <halfpacho@gmail.com> * Update sorting/count_inversions.cpp Co-authored-by: David Leal <halfpacho@gmail.com> * Update sorting/count_inversions.cpp Co-authored-by: David Leal <halfpacho@gmail.com> * Update sorting/count_inversions.cpp Co-authored-by: David Leal <halfpacho@gmail.com> * Update sorting/count_inversions.cpp Co-authored-by: David Leal <halfpacho@gmail.com> * Update sorting/count_inversions.cpp Co-authored-by: David Leal <halfpacho@gmail.com> * Update count_inversions.cpp * Update sorting/count_inversions.cpp Co-authored-by: David Leal <halfpacho@gmail.com> * Update sorting/count_inversions.cpp Co-authored-by: David Leal <halfpacho@gmail.com> * Update sorting/count_inversions.cpp Co-authored-by: David Leal <halfpacho@gmail.com> * Update count_inversions.cpp * clang-format and clang-tidy fixes for 121ce33 * Update sorting/count_inversions.cpp Co-authored-by: John Law <johnlaw.po@gmail.com> Co-authored-by: Taj <tjgurwara99@users.noreply.github.com> Co-authored-by: David Leal <halfpacho@gmail.com> Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Co-authored-by: John Law <johnlaw.po@gmail.com>
Counts the number of inversions in a list using merge sort. The number of Inversions in a list is the measure of the list's proximity to being sorted in ascending/increasing order.
Description of Change
Checklist
Notes: