in reply to Re: Fast way to check if a sort was doen
in thread Fast way to check if a sort was doen

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