News for hackers. Stuff that matters.
Re:Trying Haskell by pdhborges on Sunday April 10, 2011 @02:12PM (#2430001)
C++ quicksort :|

    #include <algorithm>
    #include <iterator>
    #include <functional>
    using namespace std;
 
    template <typename T>
    void sort(T begin, T end) {
        if (begin != end) {
            T middle = partition (begin, end,   bind2nd(less<iterator_traits<T>::value_type>(), *begin));
            sort (begin, middle);
            sort (max(begin + 1, middle), end);
        }
    }
from wikipedia
Re:Trying Haskell by chc on Sunday April 10, 2011 @03:53PM (#2430255)
His version is explicit, sort of a C++ translation of the C algorithm (though still a bit longer than necessary even for C). I think he meant to imply "in simple C++ without STL." The awkwardness of partition() is not quite enough to overcome the LOC savings, but it's making a good effort.

The Haskell version also refrains from importing the equivalent Data.List, which would allow us to define `more` and `less` as simply `partition (< x) xs`.