csinsertion_sort 0.1.3

Insertion sort implementation for indexable collections
Documentation
  • Coverage
  • 0%
    0 out of 3 items documented0 out of 2 items with examples
  • Size
  • Source code size: 4.96 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 140.83 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • cstffx/csinsertion_sort
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • cstffx

csinsertion_sort

Insertion sort algorithm implementation over a vector.

Use this create to add a insertion_sort and insertion_sort_by methods to Vec data type.

use csinsertion_sort::InsertionSort; 
    
let mut input: Vec<u32> = vec![2, 1];

// this will sort items in ascending order 
// using insertion sort algorithm
input.insertion_sort();
// input is now [1,2]

Use insertion_sort_by to customize how items are compared. As second argument pass a function with the form:

fn(a: &T, b: &T) -> bool;

This function must return true to indicate that the values are not in the correct order. For example, to sort a list of u32, in descending order, by parameter can be:

fn desc(a: u32, b: u32) -> bool {
    a < b
}

This example returns true when a=1 and b==5 in order to ensure that 5 is located at the left o 1.

For convenience asc and desc functions are provided.

use csinsertion_sort::{InsertionSort, des}; 
    
let mut input: Vec<u32> = vec![1, 2];

// this will sort items in descending order 
// using insertion sort algorithm
input.insertion_sort_by(desc);

// input is now [2,1]

To call insertion_sort is equivalent to call insertion_sort_by(asc).