How to merge sort char Array ?

This is algorithm

void Spoji(float A[],int i,int k,int j) {

int I=i, J=k+1, K=0;

float *B = new float [j-i+1];

while (I<=k && J<=j)

if (A[I]<=A[J])

B[K++]=A[I++];

else

B[K++]=A[J++];

if (I>k)

while (J<=j)

B[K++] = A[J++];

else

while (I<=k)

B[K++] = A[I++];

for (int I=0;I<=j-i;I++)

A[i+I]=B[I];

delete []B;

}

void MSort(float A[],int i, int j) {

if (i<j) {

int k=(i+j)/2;

MSort(A,i,k);

MSort(A,k+1,j);

Spoji(A,i,k,j);

}

}

void MSort(float A[],int N) {

MSort(A,0,N-1);

}

This is algorithm

void Spoji(float A[],int i,int k,int j) {

int I=i, J=k+1, K=0;

float *B = new float [j-i+1];

while (I<=k && J<=j)

if (A[I]<=A[J])

B[K++]=A[I++];

else

B[K++]=A[J++];

if (I>k)

while (J<=j)

B[K++] = A[J++];

else

while (I<=k)

B[K++] = A[I++];

for (int I=0;I<=j-i;I++)

A[i+I]=B[I];

delete []B;

}

void MSort(float A[],int i, int j) {

if (i<j) {

int k=(i+j)/2;

MSort(A,i,k);

MSort(A,k+1,j);

Spoji(A,i,k,j);

}

}

void MSort(float A[],int N) {

MSort(A,0,N-1);

}

merge sort is a recursive algorithm that separates the list into halves until each item is inits own list. After that the system combines pairs and compares the outer first pairs to see which is of lower value. if one item is lower then the other, it adds it to the back of the list. It continues until all items have been placed.

read here:

http://en.wikipedia.org/wiki/Merge_sort

read here:

http://en.wikipedia.org/wiki/Merge_sort

The FAQ page needs some work to make it less intimidating, but here it is:

http://www.cplusplus.com/faq/sequences/sequencing/sort-algorithms/mergesort/

I have no clue how you intend to understand what you are doing with that code. Whomever gave it to you is not your friend.

http://www.cplusplus.com/faq/sequences/sequencing/sort-algorithms/mergesort/

I have no clue how you intend to understand what you are doing with that code. Whomever gave it to you is not your friend.

Topic archived. No new replies allowed.