Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Fast way to check if a sort was doen

by archfool (Monk)
on Jun 28, 2007 at 15:25 UTC ( [id://623918]=note: print w/replies, xml ) Need Help??


in reply to Fast way to check if a sort was doen

Couldn't you make a flag variable and define a sort block? Concept:
$changed = 0; my @array = sort { my $result = ($a cmp $b); $changed = 1 if $result==1; # Only set changed if $a > $b $result } @oldarray;

Replies are listed 'Best First'.
Re^2: Fast way to check if a sort was doen
by dewey (Pilgrim) on Jun 28, 2007 at 19:27 UTC
    I like this idea, but I couldn't get it to work.
    my @oldarray = (0..9); my @array = sort { my $result = ($a cmp $b); print "$result "; $result } @oldarray; print "\n@array\n";
    printed these results:
    -1 -1 -1 -1 -1 -1 1 -1 1 1 1 -1 1 -1 1 1 1 1 1 0 1 2 3 4 5 6 7 8 9
    Without knowing exactly how the sorting algorithm is implemented, I don't see how we could reliably use this kind of method.

    If OP wants to write a sorting function, they can include a flag... otherwise, this problem seems pretty solidly O(N) to me.

    ~dewey

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-19 21:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found