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 Bingo Sort #642

Merged
merged 26 commits into from
Jan 2, 2024
Merged

Added Bingo Sort #642

merged 26 commits into from
Jan 2, 2024

Conversation

BogdanCiocea
Copy link
Contributor

Bingo Sort Implementation in Rust

The provided Rust code implements the bingo sort algorithm for sorting a vector of integers. The bingo sort algorithm repeatedly identifies and moves the "bingo" elements, which are elements that equal the current bingo value.

Empty Vector Check

  • If the vector is empty, the function returns early to avoid further processing.

Initializing Bingo Elements

  1. Two variables, bingo and next_bingo, are initialized with the first two elements of the vector.

Identifying Maximum and Minimum

  1. The max_min function is called to identify the maximum and minimum elements in the vector.
  2. The minimum element is stored in next_bingo for later use.

Tracking Largest Element

  1. The largest_element variable is set to next_bingo, which is the current minimum element.

Position of Next Element to Swap

  1. The next_element_pos variable keeps track of the position of the next element to swap with the current bingo element.

Sorting Loop

  1. A loop iterates over the range of bingo..=largest_element, which represents the sequence of bingo elements.

  2. Inside the loop:

    a. Initializing Start Position:

    • The start_pos variable is set to the current next_element_pos to serve as the starting position for iterating on the current bingo element.

    b. Iterating on Remaining Elements

    • The loop iterates over the remaining elements in the vector starting from the start_pos position.

      1. Swapping Equal Elements:

        • If the current element at index i equals the current bingo element bingo, then the elements at positions i and next_element_pos are swapped.
      2. Updating Next Bingo Element:

        • If the current element at index i is less than the current bingo element bingo, then it indicates that a new bingo element has been found.
        • The next_bingo variable is updated to the current element to prepare for the next iteration.

Updating Bingo and Next Bingo Elements

  1. After the loop completes, the current and next bingo elements are updated:

    • The bingo variable is updated to the current next_bingo element.
    • The next_bingo variable is reset to the largest_element to start the next iteration with the next bingo element.

This iterative process continues until all bingo elements are sorted into their correct positions.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • I ran bellow commands using the latest version of rust nightly.
  • I ran cargo clippy --all -- -D warnings just before my last commit and fixed any issue that was found.
  • I ran cargo fmt just before my last commit.
  • I ran cargo test just before my last commit and all tests passed.
  • I added my algorithm to the corresponding mod.rs file within its own folder, and in any parent folder(s).
  • I added my algorithm to DIRECTORY.md with the correct link.
  • I checked COUNTRIBUTING.md and my code follows its guidelines.

@codecov-commenter
Copy link

codecov-commenter commented Dec 31, 2023

Codecov Report

Attention: 7 lines in your changes are missing coverage. Please review.

Comparison is base (c522e60) 94.52% compared to head (faf6ce5) 94.51%.
Report is 1 commits behind head on master.

Files Patch % Lines
src/sorting/bingo_sort.rs 91.35% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #642      +/-   ##
==========================================
- Coverage   94.52%   94.51%   -0.02%     
==========================================
  Files         282      283       +1     
  Lines       22606    22687      +81     
==========================================
+ Hits        21369    21443      +74     
- Misses       1237     1244       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@siriak siriak left a comment

Choose a reason for hiding this comment

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

Looks good, thanks!

@siriak siriak merged commit 87ec8a0 into TheAlgorithms:master Jan 2, 2024
4 checks passed
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.

3 participants