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

feat: Add sorting/count_inversions.cpp #1425

Merged
merged 38 commits into from
Dec 16, 2020

Conversation

rakshitraj
Copy link
Contributor

@rakshitraj rakshitraj commented Nov 5, 2020

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

  • Added description of change
  • Added file name matches File name guidelines
  • Added tests and example, test must pass
  • Added documentation so that the program is self-explanatory and educational - Doxygen guidelines
  • Relevant documentation/comments is changed or added
  • PR title follows semantic commit guidelines
  • Search previous suggestions before making a new one, as yours may be a duplicate.
  • I acknowledge that all my contributions will be made under the project's license.

Notes:

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.
@rakshitraj
Copy link
Contributor Author

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.

@Panquesito7 Panquesito7 changed the title Create count_inversions.cpp feat: Add sorting/count_inversions.cpp Nov 5, 2020
@Panquesito7 Panquesito7 added the enhancement New feature or request label Nov 5, 2020
- fixed template error on line 156
- an added test case for character array
- an added test case for list type double
@Panquesito7 Panquesito7 requested a review from kvedala November 5, 2020 20:04
Copy link
Member

@tjgurwara99 tjgurwara99 left a 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!

sorting/count_inversions.cpp Outdated Show resolved Hide resolved
sorting/count_inversions.cpp Outdated Show resolved Hide resolved
Co-authored-by: Taj <tjgurwara99@users.noreply.github.com>
Copy link
Member

@Panquesito7 Panquesito7 left a 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

sorting/count_inversions.cpp Outdated Show resolved Hide resolved
sorting/count_inversions.cpp Outdated Show resolved Hide resolved
rakshitraj and others added 2 commits November 29, 2020 22:28
Co-authored-by: Taj <tjgurwara99@users.noreply.github.com>
Co-authored-by: David Leal <halfpacho@gmail.com>
and doxygen formatiing
@rakshitraj rakshitraj closed this Nov 29, 2020
@rakshitraj rakshitraj reopened this Nov 29, 2020
@rakshitraj
Copy link
Contributor Author

Please enable GitHub Actions in your repository of this fork in this link: https://github.com/rakshitraj/C-Plus-Plus/actions

Done. Please mark this. It is being counted as pending action.

Copy link
Member

@Panquesito7 Panquesito7 left a 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. 🙂

sorting/count_inversions.cpp Outdated Show resolved Hide resolved
sorting/count_inversions.cpp Outdated Show resolved Hide resolved
sorting/count_inversions.cpp Outdated Show resolved Hide resolved
sorting/count_inversions.cpp Show resolved Hide resolved
sorting/count_inversions.cpp Outdated Show resolved Hide resolved
sorting/count_inversions.cpp Outdated Show resolved Hide resolved
rakshitraj and others added 4 commits December 1, 2020 11:59
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>
@github-actions github-actions bot force-pushed the patch-1 branch 3 times, most recently from fcf41c4 to 0f9a744 Compare December 2, 2020 18:03
rakshitraj and others added 3 commits December 2, 2020 23:34
Co-authored-by: David Leal <halfpacho@gmail.com>
Co-authored-by: David Leal <halfpacho@gmail.com>
Co-authored-by: David Leal <halfpacho@gmail.com>
rakshitraj and others added 3 commits December 2, 2020 23:36
@Panquesito7 Panquesito7 added the requested changes changes have been requested label Dec 2, 2020
Co-authored-by: David Leal <halfpacho@gmail.com>
Co-authored-by: David Leal <halfpacho@gmail.com>
Copy link
Member

@Panquesito7 Panquesito7 left a 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! 🎉👍

sorting/count_inversions.cpp Outdated Show resolved Hide resolved
@Panquesito7 Panquesito7 added approved Approved; waiting for merge and removed requested changes changes have been requested labels Dec 3, 2020
@Panquesito7
Copy link
Member

@kvedala @ayaankhan98 please review. Thanks. 🙂

Comment on lines +233 to +234
// static void body() {
// // Input your own sequence
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

@poyea poyea left a 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!🤩

sorting/count_inversions.cpp Outdated Show resolved Hide resolved
Co-authored-by: John Law <johnlaw.po@gmail.com>
@Panquesito7
Copy link
Member

Will merge this PR. If there are any errors, please make a new PR to propose a fix. Thank you. 🙂

@Panquesito7 Panquesito7 merged commit 1f5ca99 into TheAlgorithms:master Dec 16, 2020
@rakshitraj rakshitraj deleted the patch-1 branch December 17, 2020 17:46
ayaankhan98 pushed a commit to ayaankhan98/C-Plus-Plus that referenced this pull request Feb 11, 2021
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Approved; waiting for merge enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants