Crates.io | prksort |
lib.rs | prksort |
version | 0.1.0 |
source | src |
created_at | 2024-05-15 12:34:31.495464 |
updated_at | 2024-05-15 12:34:31.495464 |
description | This is an implementation of the Merge Sort and Quick Sort algorithms in Rust |
homepage | |
repository | https://github.com/prk-Jr/prksort |
max_upload_size | |
id | 1241010 |
size | 7,247 |
This is an implementation of the Merge Sort algorithm in Rust. Merge Sort is an efficient, stable, and comparison-based sorting algorithm known for its performance.
To use the sort
function provided in this module, simply call it with a mutable reference to a vector of comparable elements.
use prksort::*;
let mut arr = vec![5, 2, 3, 1, 4];
mergesort::sort(&mut arr);
println!("Sorted array: {:?}", arr); // Output: Sorted array: [1, 2, 3, 4, 5]
This will sort the elements of the vector in ascending order.
The sort
function works with any type T
that implements the PartialEq
, PartialOrd
, and Copy
traits. This means that the elements of the vector must support comparisons and be copyable.
use prksort::*;
let mut arr = vec!['e', 'b', 'c', 'a', 'd'];
mergesort::sort(&mut arr);
println!("Sorted array: {:?}", arr); // Output: Sorted array: ['a', 'b', 'c', 'd', 'e']
The sort
function sorts the input vector in-place using the Merge Sort algorithm.
The merge
function is a helper function used by the sort
function to merge two sorted slices into one sorted slice.
## License
This code is provided under the MIT License. You can find the full license text in the LICENSE file.
## Contribution
Contributions are welcome! If you find any issues or have suggestions for improvements, feel free to open an issue or create a pull request on GitHub.
This is an implementation of the Quick Sort algorithm in Rust. Quick Sort is a widely used sorting algorithm known for its efficiency and simplicity.
To use the sort
function provided in this module, simply call it with a mutable reference to an array or slice of comparable elements.
use prksort::*;
let mut arr = vec![5, 2, 3, 1, 4];
quicksort::sort(&mut arr);
println!("Sorted array: {:?}", arr); // Output: Sorted array: [1, 2, 3, 4, 5]