all tasks
This commit is contained in:
parent
b83f433714
commit
68f8f3e56b
14735 changed files with 178959 additions and 0 deletions
|
|
@ -0,0 +1,24 @@
|
|||
use strict;
|
||||
|
||||
sub gnome_sort
|
||||
{
|
||||
my @a = @_;
|
||||
|
||||
my $size = scalar(@a);
|
||||
my $i = 1;
|
||||
my $j = 2;
|
||||
while($i < $size) {
|
||||
if ( $a[$i-1] <= $a[$i] ) {
|
||||
$i = $j;
|
||||
$j++;
|
||||
} else {
|
||||
@a[$i, $i-1] = @a[$i-1, $i];
|
||||
$i--;
|
||||
if ($i == 0) {
|
||||
$i = $j;
|
||||
$j++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return @a;
|
||||
}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
my @arr = ( 10, 9, 8, 5, 2, 1, 1, 0, 50, -2 );
|
||||
print "$_\n" foreach gnome_sort( @arr );
|
||||
Loading…
Add table
Add a link
Reference in a new issue