Skip to content

Conversation

anishk85
Copy link

@anishk85 anishk85 commented Oct 5, 2025

Merge Sort in Rust

This folder contains an implementation of the Merge Sort algorithm in Rust.

Algorithm Overview

Merge Sort is a classic divide-and-conquer sorting algorithm. It works by recursively splitting the array into halves, sorting each half, and then merging the sorted halves back together. Merge Sort has a time complexity of O(n log n) and is stable, making it suitable for large datasets.

Screenshot from 2025-10-05 21-23-06

Features

  • Generic Implementation: Works with any type that implements Ord and Clone.
  • Unit Tests: Includes tests for various edge cases and typical scenarios.
  • Examples: Demonstrates sorting integers and strings.

Usage

To run the example and tests:

rustc merge_sort.rs && ./merge_sort
rustc --test merge_sort.rs && ./merge_sort

Example

let mut numbers = vec![64, 34, 25, 12, 22, 11, 90];
merge_sort(&mut numbers);
println!("{:?}", numbers); // Output: [11, 12, 22, 25, 34, 64, 90]

References


Contributed as part of Hacktoberfest 2025.

@anishk85
Copy link
Author

anishk85 commented Oct 5, 2025

@thuva4 kindly review this i have also attached the picture of algorithm submission on leetcode.
also kindly merge this pr if there were no issues.
I would love contributing in more algorithms in rust.
thanks

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