rendered paste body
#include "mySort.h"
void merge (int array[] ,int first, int mid, int last);
void mySort(int array[], unsigned int first, unsigned int last)
{
int mid,tmp;
int num;
num=(last-first)+1;
if (num>2)
{
mid = (first + last)/2;
mySort (array, first, mid);
mySort (array, (mid+1), last);
printf("f:%i m:%i l:%i\n\n",first,mid,last);
merge (array,first, mid, last);
}
else if (num==2)
{
if (array[first]>array[last])
{
tmp=array[first];
array[first]=array[last];
array[last]=tmp;
}
}
}
void merge (int array[], int first, int mid, int last)
{
int num;
int i,j;
int temp_pos,temp_pos2,f_temp;
int temp[MAX_SIZE_N_TO_SORT];
int flag;
num= (last-first) + 1;
for (i=first;i<num;i++)
temp[i]=array[i];
//Merges top first half and second half and sorts
temp_pos=first;
temp_pos2=mid+1;
f_temp=first;
flag=0;
for (i=0;i<num;i++)
{
if (temp_pos2>last)
{
for(j=temp_pos;j<=mid;j++)
{
array[f_temp]=temp[j];
printf("array:%i:%i\n", array[f_temp],f_temp);
f_temp++;
}
break;
}
if (temp_pos >mid)
{
for (j=temp_pos2;j<=last;j++)
{
array[f_temp]=temp[j];
printf("array:%i:%i\n", array[f_temp],f_temp);
f_temp++;
}
break;
}
/* if (temp_pos>mid)
break;
if (temp_pos2>last)
break;
printf ("temp_pos: %i temp_pos2 %i \n",temp_pos,temp_pos2);
/*if (temp_pos>mid&&flag==0)
{
temp_pos=temp_pos2;
temp_pos2++;
flag=1;
}*/
if (temp[temp_pos]>=temp[temp_pos2])
{
array[f_temp]=temp[temp_pos2];
printf("array:%i:%i\n", array[f_temp],f_temp);
temp_pos2++;
}
else if (temp[temp_pos]<temp[temp_pos2])
{
array[f_temp]=temp[temp_pos];
printf("array:%i:%i\n", array[f_temp],f_temp);
temp_pos++;
}
/*else if (temp[temp_pos]==temp[temp_pos2])
{
array[f_temp]=temp[temp_pos];
printf("array:%i:%i\n", array[f_temp],f_temp);
temp_pos++;
array[f_temp]=temp[temp_pos2];
printf("array:%i:%i\n", array[f_temp],f_temp);
temp_pos++;
}*/
f_temp++;
}
/*if (temp_pos2>last)
{
for(j=temp_pos;j<=mid;j++)
{
array[f_temp]=temp[j];
printf("array:%i:%i\n", array[f_temp],f_temp);
f_temp++;
}
}
if (temp_pos >mid)
{
for (j=temp_pos2;j<last;j++)
{
array[f_temp]=temp[j];
printf("array:%i:%i\n", array[f_temp],f_temp);
f_temp++;
}
}
*/
}