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

Added code snippets of C++ on bit manipulation, math & number, searching, sorting #217

Merged
merged 5 commits into from
Jan 12, 2025

Conversation

ashukr07
Copy link
Contributor

@ashukr07 ashukr07 commented Jan 8, 2025

Description

Added code snippets for C++:

  1. Math and Number Category snippets:

    • Binary to decimal conversion
    • Check if the number is perfect number
    • Calculate the factorial of a number using recursion
    • Find the nth fibonacci number using recursion
    • Calculate greatest comman divisor(GCD)
    • Calculate the least comman multiple(LCM)
    • Calculate the sum of digits of a number
  2. Added new Bit Manipulation Category

    • Check if a given number is power of 2
    • Count set bits in a number
    • Find the non repeating number in array
    • Reverse bits
    • Calculate the XOR over 1 to n(provided by user)
  3. Added new Searching Category

    • Linear Search
    • Binary Search
  4. Added new Sorting Category

    • Bubble sort
    • Insertion sort
    • Merge sort
    • Quick sort
    • Selection sort

Type of Change

  • ✨ New snippet
  • 🛠 Improvement to an existing snippet
  • 🐞 Bug fix
  • 📖 Documentation update
  • 🔧 Other (please describe):

Checklist

  • I have tested my code and verified it works as expected.
  • My code follows the style and contribution guidelines of this project.
  • Comments are added where necessary for clarity.
  • Documentation has been updated (if applicable).
  • There are no new warnings or errors from my changes.

Related Issues

Closes #

Additional Context

Screenshots (Optional)

Click to view screenshots

@ashukr07 ashukr07 requested a review from saminjay as a code owner January 8, 2025 19:59
@saminjay
Copy link
Collaborator

saminjay commented Jan 9, 2025

A lot of the bit manipulation should be moved to C. They are not exactly specific for C++, except for the vector one.
C++ STL provides functions for sorting and searching. They don't need to be in the Snippets.

@ashukr07
Copy link
Contributor Author

ashukr07 commented Jan 9, 2025

A lot of the bit manipulation should be moved to C. They are not exactly specific for C++, except for the vector one. C++ STL provides functions for sorting and searching. They don't need to be in the Snippets.

Ok I will remove the searching and sorting part from the snippets.
But for bit manipulation it is not only for c, we could also do bit manipulation in C++. So we could keep that in both the languages

@majvax
Copy link
Collaborator

majvax commented Jan 9, 2025

Hey, I understand that bit manipulation isn't exclusive to C and can also be done in C++. However, since the snippets don't use any C++-specific features (at least no big one) and are more aligned with C-style programming, it makes sense to categorize them under C.

@ashukr07
Copy link
Contributor Author

Hey, I understand that bit manipulation isn't exclusive to C and can also be done in C++. However, since the snippets don't use any C++-specific features (at least no big one) and are more aligned with C-style programming, it makes sense to categorize them under C.

Got it, thanks for pointing out. I’ll make the changes to categorize the snippets under C accordingly.

@ashukr07
Copy link
Contributor Author

I have moved all the snippets of bit manipulation to C except the find the non repeating element in vector as vector is supported only in C++.
I have also removed the searching and sorting snippets and gcd and lcm snippets as it is present in C++ stl.

@ashukr07 ashukr07 requested a review from saminjay January 10, 2025 06:10
Copy link
Collaborator

@Mathys-Gasnier Mathys-Gasnier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some little misplacements of files, but overall great work

@ashukr07
Copy link
Contributor Author

All the mentioned snippets moved to C

Copy link
Collaborator

@Mathys-Gasnier Mathys-Gasnier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work thanks !

@Mathys-Gasnier Mathys-Gasnier merged commit cade4dd into technoph1le:main Jan 12, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants