in reply to Re: How do i sort an numeric array without using sort function. Is ther any way to sort it just with loop in perl??
in thread How do i sort an numeric array without using sort function. Is ther any way to sort it just with loop in perl??
If i do any mistake its bcs im new in perl
I didnt get any output
#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my @unsorted = map {int (1000 * rand ())} (1..100); my @sorted = sort_try (@unsorted); print Dumper \ @sorted; sub sort_try { my $i = 0; while ($i < $#unsorted) { if ($unsorted[$i] > $unsorted[$i+1]) { @unsorted[$i, $i+1] = @unsorted[$i+1, $i]; --$i if $i; } else { ++$i; } } return @unsorted; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: How do i sort an numeric array without using sort function. Is ther any way to sort it just with loop in perl??
by hippo (Bishop) on Nov 02, 2017 at 10:05 UTC | |
by Tabish (Acolyte) on Nov 02, 2017 at 10:18 UTC | |
by Random_Walk (Prior) on Nov 02, 2017 at 11:22 UTC |
In Section
Seekers of Perl Wisdom