12void compAndSwap(
int a[],
int i,
int j,
int dir) {
13 if (dir == (a[i] > a[j]))
14 std::swap(a[i], a[j]);
21void bitonicMerge(
int a[],
int low,
int cnt,
int dir) {
24 for (
int i = low; i < low +
k; i++) compAndSwap(a, i, i + k, dir);
25 bitonicMerge(a, low, k, dir);
26 bitonicMerge(a, low + k, k, dir);
33void bitonicSort(
int a[],
int low,
int cnt,
int dir) {
38 bitonicSort(a, low, k, 1);
41 bitonicSort(a, low + k, k, 0);
45 bitonicMerge(a, low, cnt, dir);
51void sort(
int a[],
int N,
int up) { bitonicSort(a, 0, N, up); }
55 int a[] = {3, 7, 4, 8, 6, 2, 1, 5};
56 int N =
sizeof(a) /
sizeof(a[0]);
61 std::cout <<
"Sorted array: \n";
62 for (
int i = 0; i <
N; i++) std::cout << a[i] <<
" ";
double k(double x)
Another test function.
constexpr uint32_t N
A struct to represent sparse table for min() as their invariant function, for the given array A....