-
Notifications
You must be signed in to change notification settings - Fork 71
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
Conversation
There was a problem hiding this 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.
src/sorting/quick_sort.rs
Outdated
/// 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). |
There was a problem hiding this comment.
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 👍🏻
src/sorting/quick_sort.rs
Outdated
// 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); | ||
} | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
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?
src/sorting/quick_sort.rs
Outdated
use crate::sorting::QuickSort; | ||
use crate::sorting::quicksort::QuickSort; | ||
|
||
sorting_tests!(QuickSort::sort, quick_sort); | ||
sorting_tests!(QuickSort::sort_inplace, quick_sort, inplace); |
There was a problem hiding this comment.
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?
#[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); | ||
} |
There was a problem hiding this comment.
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.
Closing for bookkeeping purposes! |
No description provided.