Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Sorting algorithms

Name: Anonymous 2007-08-01 12:56 ID:otd2+Ec4

Lets talk about them! Which ones do you like/use/have implemented/have invented/etc.?

Code related:

    // A spectacular variant of bogo-sort which has the interesting property
    // that, if the Many Worlds interpretation of quantum mechanics is true, it
    // can sort an arbitrarily large array in linear time.
    static BogoSort(arrayToSort : array [int]) : void
    {
        // permute the array randomly using a quantum process
        def rnd = Random(DateTime.Now.Millisecond);
        def sort(left = 0)
        {
            when (left < arrayToSort.Length - 1)
            {
                def right = rnd.Next(left, arrayToSort.Length);
                def tmp = arrayToSort[left];
                arrayToSort[left] = arrayToSort[right];
                arrayToSort[right] = tmp;
                sort(left + 1);
            }
        }
        sort();

        // check if array is sorted
        def check(left = 0)
        {
            def right = left + 1;
            when (right < arrayToSort.Length)
            {
                if (arrayToSort[left] < arrayToSort[right])
                    check(right);
                else
                    throw Exception("Sort failed! Please destroy the universe. :(");
            }
        }
        check();
    }

Name: Anonymous 2007-08-01 18:32 ID:8xJbQiwv

>>15

Shit

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List