in reply to
Re: Sorting Arrays Without using SORT function
in thread Sorting Arrays Without using SORT function
If PC isn't allowed to use the sort function, then List::Util is probably even more forbidden.
use strict;
use warnings;
my @array = qw(h o m e w o r k);
while (not isSorted(@array))
{
print +(join ", ", @array) . "\r";
my ($x, $y) = (rand(scalar @array), rand(scalar @array));
($array[$x], $array[$y]) = ($array[$y], $array[$x]);
}
print "\nSort complete!\n";
print join ", ", @array;
sub isSorted
{
my $x = shift;
while (my $y = shift)
{
return 0 unless ($x cmp $y) < 1;
$x = $y;
}
return 1;
}