Freigeben über


QuickSort

I have just written a simple class that implements QuickSort algorithm and allows sorting of some "keys" by their "values".

And this is how it may be used:

    static void exampleQuickSort(Args _args)

    {

        QuickSort quickSort;

        ListEnumerator itemEnumerator;

        str itemId;

        Qty qty;

        ;

        quickSort = QuickSort::construct(Types::String, Types::Real);

        quickSort.add('Item1', 10.00);

        quickSort.add('Item2', 12.00);

        quickSort.add('Item3', 9.00);

        itemEnumerator = quickSort.getEnumerator();

        while (itemEnumerator.moveNext())

        {

            [itemId, qty] = itemEnumerator.current();

            print itemId, ' ', qty;

        }

        pause;

    }

The output will look like this:

Item3 9,00
Item1 10,00
Item2 12,00

You may find the class in the attachment.

Class_QuickSort.xpo