Anonymous user
Sorting algorithms/Bubble sort: Difference between revisions
m
→[[Perl]]
m (→[[Toka]]: Added full example and further comments) |
m (→[[Perl]]) |
||
Line 206:
'''Interpreter:''' perl 5.8.8
# Sorts an array in place and returns a copy▼
sub bubble_sort (@) {▼
▲# Sorts an array in place and returns a copy
▲sub bubble_sort (@) {
for my $
for my $
}▼
return @_;▼
▲}
# usage▼
@a = qw/G F C A B E D/; ▼
▲# usage
bubble_sort(@a);▼
▲@a = qw/G F C A B E D/;
▲bubble_sort(@a);
Alternate "Long Hand" Perl Method
sub Bubble_Sort {▼
▲sub Bubble_Sort {
my
my $
my $
▲ my $elements = $#list + 1;
while ($done == 0) {
for (my $
$
$
return @list;
}
# usage▼
my @test = (1, 3, 256, 0, 3, 4, -1);▼
print join(",", Bubble_Sort(@test));▼
▲ # usage
▲ my @test = (1, 3, 256, 0, 3, 4, -1);
▲ print join(",", Bubble_Sort(@test));
==[[Pop11]]==
|