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

first commit #367

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

first commit #367

wants to merge 1 commit into from

Conversation

Anshv9616
Copy link

Use of std::vector:

Replaced the raw array with std::vector, which allows for dynamic sizing and better memory management.
Tracking Last Swap Position:

Introduced a variable lastSwapIndex to track the last position where a swap occurred. This helps to reduce the number of comparisons in subsequent passes, as any elements after this index are already sorted.
Const-Correctness:

Changed the display function to take a const vector& instead of a raw pointer. This emphasizes that the function does not modify the input vector.
Minor Code Cleanups:

Streamlined the swapping function by initializing temp directly.
Used a range-based for loop in the display function for improved readability.
These changes collectively improve both performance and clarity while maintaining the core functionality of the Bubble Sort algorithm.

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