Skip to content

Instantly share code, notes, and snippets.

@Puriney
Created June 20, 2013 04:04
Show Gist options
  • Save Puriney/5820231 to your computer and use it in GitHub Desktop.
Save Puriney/5820231 to your computer and use it in GitHub Desktop.
PERL: insertion_sort
# subroutine to implement insertion_sorting
#!/usr/bin/perl -w
sub insertion_sort {
my (@list) = @_;
foreach my $i (1 .. $#list){
my $j = $i;
my $tmp = $list[$i];
while ($j >0 && $tmp < $list[$j-1]){
$list[$j] = $list[$j-1];
$j --;
}
$list[$j]=$tmp;
}
return @list;
}
my @test = &insertion_sort(1,2,-1,3,0);
print "@test\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment