batcher

 

// test batcher
#include <iostream>
using namespace std;
#include „prob-16-kern.h”
#include „prob-16-bope.h”
extern int currentpoint;
int sizeofpoint = 12;
int pointdata;     // 4 bytes
int k;              // 4 bytes
int c;             // 4 bytes
int main()
{
int A;
   srand((int)time(0));       // initialize random number generator
    xpand(15);                  // expand to subbase 1111
    pointdata = rand() % 100;    // some random number 0,1,2,… 99
    cout << „orig data          ” << currentpoint << ”  ” << pointdata << ” \n”;
    for (k = 2; k <= 16; k = k << 1) {
        for (c = k >> 1; c > 0; c = c >> 1) {
            A = pointdata;
            t(c);
            // batcher sort runs through series of t(c), for c = 1 / 2,1 / 4,2,1 / 8,4,2,1 / …
            // after each t(c) exchanging A <–> pointdata on both sides of edge c
            // if (arrow at currentpoint) and (A > pointdata) pointdata= A;
            // if not (arrow at currentpoint) and (A < pointdata) pointdata= A;
            // meaning of „arrow” … see drawing of batcher sort in text „a new approach .. „
            if ((inner(currentpoint, (k ^ c)) == 1) && (A > pointdata)) pointdata = A;
            if ((inner(currentpoint, (k ^ c)) == 0) && (A < pointdata)) pointdata = A;
        }
    }
    cout << „sorted ” << currentpoint << ”  ” << pointdata << ” \n”;
    o();
}