qsort-rs 0.1.1

A quick sort algorithm that accepts any type and non-recursive approach.
Documentation
  • Coverage
  • 66.67%
    2 out of 3 items documented1 out of 2 items with examples
  • Size
  • Source code size: 20.20 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 173.59 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • Homepage
  • LorenzoLeonardo/qsort-rs
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • LorenzoLeonardo

qsort-rs

A quick sort algorithm that accepts any type and non-recursive approach.

Latest Version License Documentation Build Status

How to use this function

use qsort_rs::qsort;

#[derive(Ord, PartialEq, PartialOrd, Eq, Debug)]
struct Student {
    name: String,
    age: u32,
    gender: String,
}

fn main() {
    let mut arr = [
        Student {
            name: String::from("Zed"),
            age: 3,
            gender: String::from("Male"),
        },
        Student {
            name: String::from("Aubrey"),
            age: 13,
            gender: String::from("Female"),
        },
        Student {
            name: String::from("Jaime"),
            age: 6,
            gender: String::from("Male"),
        },
        Student {
            name: String::from("Irene"),
            age: 8,
            gender: String::from("Female"),
        },
        Student {
            name: String::from("Ren"),
            age: 9,
            gender: String::from("Male"),
        },
    ];

    qsort::sort(&mut arr, |low, high| low.name <= high.name);

    assert_eq!(
        arr,
        [
            Student {
                name: "Aubrey".to_string(),
                age: 13,
                gender: "Female".to_string()
            },
            Student {
                name: "Irene".to_string(),
                age: 8,
                gender: "Female".to_string()
            },
            Student {
                name: "Jaime".to_string(),
                age: 6,
                gender: "Male".to_string()
            },
            Student {
                name: "Ren".to_string(),
                age: 9,
                gender: "Male".to_string()
            },
            Student {
                name: "Zed".to_string(),
                age: 3,
                gender: "Male".to_string()
            }
        ]
    )
}