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

ref: organize QuickSort comments #64

Closed
wants to merge 4 commits into from

Conversation

abeybernard
Copy link
Contributor

No description provided.

Copy link
Owner

@alexfertel alexfertel left a comment

Choose a reason for hiding this comment

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

Hello! Thanks for your contribution.

I think the only applicable change here is the improvement on the comments. So if you revert the rest, I'm happy to merge the PR.

Also, please take a minute to read https://github.com/alexfertel/rust-algorithms/blob/main/CONTRIBUTING.md before opening any other PRs.

Comment on lines 1 to 15
/// Sorts an array using the QuickSort algorithm.
///
/// QuickSort is a Divide and Conquer algorithm. It picks an element as a pivot and partitions
/// the given array around the picked pivot.
///
/// # Parameters
///
/// - `array`: A mutable reference to the array to be sorted.
///
/// The key process in QuickSort is a partition. The target of partitions is, given an array and an
/// element `x` of an array as the pivot, put `x` at its correct position in a sorted array and put
/// all smaller elements (smaller than `x`) before `x`, and put all greater elements (greater than `x`)
/// after `x. All this should be done in linear time.
///
/// QuickSort's time complexity is O(n*logn).
Copy link
Owner

Choose a reason for hiding this comment

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

I like this change, it is an improvement 👍🏻

Comment on lines 63 to 92
// Example module organization structure
mod sorting {
pub mod traits {
pub trait Sorter<T> {
fn sort_inplace(array: &mut [T]);
}
}

pub mod quicksort {
use super::traits::Sorter;

/// Sorts an array using the QuickSort algorithm.
pub fn quick_sort<T: Ord>(array: &mut [T]) {
// ... (QuickSort implementation)
}

/// QuickSort is a type that implements the `Sorter` trait for QuickSort.
pub struct QuickSort;

impl<T> Sorter<T> for QuickSort
where
T: Ord + Copy,
{
fn sort_inplace(array: &mut [T]) {
quick_sort(array);
}
}
}
}

Copy link
Owner

Choose a reason for hiding this comment

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

Could we remove this bit?

Comment on lines 60 to 63
use crate::sorting::QuickSort;
use crate::sorting::quicksort::QuickSort;

sorting_tests!(QuickSort::sort, quick_sort);
sorting_tests!(QuickSort::sort_inplace, quick_sort, inplace);
Copy link
Owner

Choose a reason for hiding this comment

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

Could we revert these changes?

@alexfertel alexfertel changed the title The code has been refined with clear documentation comments using Rust's /// notation to explain the functionality of the QuickSort algorithm and its parameters. It also utilizes Rust's range syntax for subarray operations, enhancing code conciseness and readability. Furthermore, the code is organized into modules as per Rust's recommended practices, promoting better code structure. ref: Organize QuickSort comments Oct 22, 2023
@alexfertel alexfertel changed the title ref: Organize QuickSort comments ref: organize QuickSort comments Oct 22, 2023
Comment on lines -57 to -64
#[cfg(test)]
mod tests {
use crate::sorting::traits::Sorter;
use crate::sorting::QuickSort;

sorting_tests!(QuickSort::sort, quick_sort);
sorting_tests!(QuickSort::sort_inplace, quick_sort, inplace);
}
Copy link
Owner

Choose a reason for hiding this comment

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

Please add the tests back.

@alexfertel
Copy link
Owner

Closing for bookkeeping purposes!

@alexfertel alexfertel closed this Jan 20, 2024
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.

2 participants