Skip to content

Conversation

@Aditya-354
Copy link

Description of Change

This PR fixes and improves two example snippets in the "Self-test examples" section of CONTRIBUTING.md:

  1. Improved quick_sort example

    • Replaced the overly complex expression
      int(std::end(arr) - std::begin(arr)) - 1
      with the clearer and equivalent arr.size() - 1.
    • This improves readability and makes the example easier for beginners to understand.
  2. Fixed and optimized is_number_on_array example

    • The original loop used sizeof(arr) / sizeof(int) which is incorrect for vectors and results in invalid iteration.
    • Replaced it with a safer and correct loop using arr.size().
    • Further improved it by converting the loop to a modern range-based for-loop:
      for (const auto &x : arr) {
          if (x == number) return true;
      }
    • This makes the example more idiomatic, readable, and efficient.

These changes enhance correctness, clarity, make it more beginner-friendly, and implement modern C++ best practices in the contribution examples.

Checklist

  • Added description of change
  • Updated example documentation/code
  • PR title follows semantic commit guidelines
  • I acknowledge that all my contributions will be made under the project's license.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant