On Sunday, 8 June 2014 at 08:44:42 UTC, monarch_dodra wrote: 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;
}

I'm partial to MiracleSort[1] myself.

void main() {
    import core.thread;
    immutable period = 1.seconds;
    auto data = [2, 7, 4, 3, 5, 1, 0, 9, 8, 6, -1];

    while (!isSorted(data)) {
        Thread.sleep(period);
    }

    data.writeln();
}


[1]: http://stackoverflow.com/questions/2609857/are-there-any-worse-sorting-algorithms-than-bogosort-a-k-a-monkey-sort/6947808#6947808

Reply via email to