Permutation Sort Algorithm Very Slow
monarch_dodra via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Jun 8 01:44:41 PDT 2014
On Saturday, 7 June 2014 at 22:01:25 UTC, Ali GOREN wrote:
> Thank you. I can not resolve it in quicker time, right?
Depends what exactly you want to achieve. This will achieve the
same result in a fraction of the time.
void main() {
auto data = [2, 7, 4, 3, 5, 1, 0, 9, 8, 6, -1];
sort(data);
data.writeln;
}
But it's not "permutation sort". Honestly, I've never *heard* of
"permutation sort". In any case, it's one of the worst sorts I've
ever heard of.
If you want to use a bad algorithm, you could also go for
bogosort:
void main() {
auto data = [2, 7, 4, 3, 5, 1, 0, 9, 8, 6, -1];
while (!isSorted(data))
randomShuffle(data);
data.writeln;
}
More information about the Digitalmars-d-learn
mailing list