Skip to content

Improve bubble sort implementation by adding memory allocation check#1583

Open
dhruvatr wants to merge 1 commit into
TheAlgorithms:masterfrom
dhruvatr:patch-1
Open

Improve bubble sort implementation by adding memory allocation check#1583
dhruvatr wants to merge 1 commit into
TheAlgorithms:masterfrom
dhruvatr:patch-1

Conversation

@dhruvatr

Copy link
Copy Markdown

Description of Change

References

Checklist

  • Added description of change
  • Added file name matches File name guidelines
  • Added tests and example, test must pass
  • 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:

Summary

This PR improves the bubble sort implementation by making the code more robust and following C best practices.

Changes

  • Added a NULL check after calloc() to handle memory allocation failures.
  • Removed the unnecessary cast from calloc().
  • Eliminated unused main() parameters.
  • Fixed a typo in the comment ("Intializes" → "Initializes").

These changes improve code quality without affecting the algorithm's behavior.

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