Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: Sorting Arrays Without using SORT function

by SuicideJunkie (Priest)
on Feb 15, 2011 at 17:53 UTC ( #888330=note: print w/ replies, xml ) Need Help??


in reply to Re: Sorting Arrays Without using SORT function
in thread Sorting Arrays Without using SORT function

If PC isn't allowed to use the sort function, then List::Util is probably even more forbidden.

use strict; use warnings; my @array = qw(h o m e w o r k); while (not isSorted(@array)) { print +(join ", ", @array) . "\r"; my ($x, $y) = (rand(scalar @array), rand(scalar @array)); ($array[$x], $array[$y]) = ($array[$y], $array[$x]); } print "\nSort complete!\n"; print join ", ", @array; sub isSorted { my $x = shift; while (my $y = shift) { return 0 unless ($x cmp $y) < 1; $x = $y; } return 1; }


Comment on Re^2: Sorting Arrays Without using SORT function
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://888330]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (16)
As of 2014-07-10 20:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (215 votes), past polls