On Wed, Sep 30, 2015 at 8:04 PM
Hi!
I'm a C++ beginner and any help would be very much appreciated. I would like to convert this "std::sort" into "boost::sort::spreadsort::integer_sort".
I recommend looking at the examples in the documentation: http://www.boost.org/doc/libs/develop/libs/sort/doc/html/sort/sort_hpp/integ...
I know that I have to write "#include
" in my header instead of "#include <algorithm>" but after that, this is too difficult... Thanks!
------------------------------------------------------------------- #include <iostream> #include <algorithm>
#include
struct rightshift { rightshift(const int *const indexed_array) : nb1(indexed_array) {} inline int operator()(int x, unsigned offset) { return nb1[x] >> offset; } const int *const nb1; };
int main() {
int nb1[4] = {15, 5, 0, 20}; int nb2[4] = {99,102, 8, 2}; int indices[4];
// integer_sort just calls std::sort when there are less than 1000 inputs. // I tested with this code: constexpr int length = 10000; int nb1[length]; int nb2[length]; int indices[length]; for (int i = 0; i < length; ++i) { nb1[length - i - 1] = 2 * i; nb2[i] = i; indices[i] = i; }
for (short i=0; i<4; i++) indices[i]=i;
sort(begin(indices), end(indices), [&](int i1, int i2) { return nb1[i1] < nb1[i2]; } );
integer_sort(begin(indices), end(indices), rightshift(nb1), [&](int i1, int i2) { return nb1[i1] < nb1[i2]; });
for (short i=0; i<4; i++) cout << nb1[indices[i]] << ' '; cout <
return 0; } --------------------------------------------------------------------- _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users