odd-even mergesort (Batchers mergesort)

I am having difficulty implementing the merge function of an odd-even merge of a mergesort. I am a bit confused on the shuffle, unshuffle routine and the recursive nature of the merge portion itself. Any help would be appreciated. This is what I have so far.

void mergesort(int A[], int B[], int left, int right)
{
int mid = (left + right)/2;
if (left == right) return;
mergesort(A, B, left, mid);
mergesort(A, B, mid + 1, right);

int C[32];
domerge(A, B, C, left, right);
}


void domerge(int A[], int B[], int C[], int left, int right)
{

if (right == left + 1)
{
C[left] = A[left];
C[left + 1] = temp[left];

if(C[left] > C[left + 1])
{
int swap;
swap = C[left];
C[left] = C[left + 1];
C[left + 1] = swap;
}
}

if (right >= left)
return;
else
{
domerge(A, B, C, left, right);
domerge(A, B, C, left, right);
}

}
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories