Permutation Sort Algorithm Very Slow

Ali GOREN via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sun Jun 8 04:37:06 PDT 2014


@monoarch_dodra

I solved BogoSort

import std.stdio, std.algorithm, std.random;

void bogoSort(T)(T[] data) {
     while (!isSorted(data))
         randomShuffle(data);
}

void main() {
     auto array = [2, 7, 41, 11, 3, 1, 6, 5, 8];
     bogoSort(array);
     writeln(array);
}

https://github.com/agoren/AlgorithmSolved/blob/master/BogoSort/main.d



More information about the Digitalmars-d-learn mailing list