Algorithm::SISort - Select And Insert sorting algorithm
use Algorithm::SISort qw(Sort Sort_inplace); @sorted_list = Sort {$_[0] <=> $_[1]} @unsorted_list; # ... or ... $number_of_comparisons = Sort_inplace {$_[0] <=> $_[1]} @unsorted_list;
This module implements a sorting algorithm I saw in BIT 28 (1988) by István Beck and Stein Krogdahl. This implementation is mainly intended to try out the Inline module by Brian Ingerson. The algorithm is a combination of Straight Insertion Sort and Selection Sort. While Insertion Sort and Selection Sort both are of complexity O(n**2), Select and Insert Sort should have complexity O(n**1.5).
This module defines the functions Sort and Sort_inplace, which have signatures similar to the internal sort function. The difference is that a codref defining a comparison is always required and that the two values to compare are always passed in @_ and not as $a and $b. (Although I might change that later.)
Sort
Sort_inplace
sort
@_
$a
$b
Sort returns a sorted copy if the array, but Sort_inplace sorts the array in place (as the name suggests) and returns the number of comparisons done. (Note that the sorting is always done in place, Sort just copies the array before calling the internal sort routine.)
Bug-reports are very welcome on the CPAN Request Tracker at:
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Algorithm-SISort
Inline, Inline::C, and A Select And Insert Sorting Algorithm by István Beck and Stein Krogdahl in BIT 28 (1988), 726-735.
Hrafnkell F. Hlodversson, keli@panmedia.dk
Copyright 2001, Hrafnkell F Hlodversson
All Rights Reserved. This module is free software. It may be used, redistributed and/or modified under the terms of the Perl Artistic License.
See http://www.perl.com/perl/misc/Artistic.html
1 POD Error
The following errors were encountered while parsing the POD:
Non-ASCII character seen before =encoding in 'István'. Assuming CP1252
To install Algorithm::SISort, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Algorithm::SISort
CPAN shell
perl -MCPAN -e shell install Algorithm::SISort
For more information on module installation, please visit the detailed CPAN module installation guide.