in reply to Insert Into a Sorted Array
my @ary = (1..4, 6..10); print "@ary\n"; for my $val( 0, 5, 11 ) { bubble( \@ary, $val ); print "@ary\n"; } sub bubble { unshift @{$_[0]}, $_[1]; for my $i( 0..@{$_[0]}-2 ) { last if $_[0]->[$i] <= $_[0]->[$i+1]; ( $_[0]->[$i],$_[0]->[$i+1] ) = ( $_[0]->[$i+1],$_[0]->[$i] ) } } __DATA__ 1 2 3 4 6 7 8 9 10 0 1 2 3 4 6 7 8 9 10 0 1 2 3 4 5 6 7 8 9 10 0 1 2 3 4 5 6 7 8 9 10 11
cheers
tachyon
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Insert Into a Sorted Array
by ketema (Scribe) on Sep 29, 2004 at 03:20 UTC | |
by ikegami (Patriarch) on Sep 29, 2004 at 03:22 UTC | |
by tachyon (Chancellor) on Sep 29, 2004 at 04:03 UTC | |
by ketema (Scribe) on Sep 29, 2004 at 03:33 UTC | |
by tachyon (Chancellor) on Sep 29, 2004 at 03:31 UTC |