[ create a new paste ] login | about

Link: http://codepad.org/1o3cqrAX    [ raw code | fork ]

Evetro - C++, pasted on Feb 23:
// non-recursive, single-threaded bitonic sort
template <class RanIt>
void bitonicSort (RanIt begin, RanIt end)
{
  const Index len = end - begin;
  for (Index i = 2; i <= len; i *= 2) 
  {
    for (Index j = i; 1 < j; j /= 2)
    {
      const Index half_j = j / 2;
      for (Index k = 0; k < len; k += j) 
      {
        const bool up = (k & i) == 0;
        for (RanIt p = begin + k, pe = p + half_j; p != pe; ++p)
        {
          if (up == p[half_j] < *p)
            std::swap (*p, p[half_j]);
        }
      }
    }
  }
}


Create a new paste based on this one


Comments: