我正在尝试为合并排序编写以下代码,任何人都可以告诉我代码有什么问题:-
#include<stdio.h>
#include<stdlib.h>
int arr[100];
void merge(int low,int mid,int high)
{
int temp[100],lowind = low,highind = mid+1,i=0;
while(lowind <= mid && highind<=high)
{
if(arr[lowind]<arr[highind])
{
temp[i] = arr[lowind];
i++;
lowind++;
}
else
{
temp[i] = arr[highind];
i++;
highind++;
}
}
while(lowind<=mid)
{
temp[i] = arr[lowind];
i++;
lowind++;
}
while(highind<=high)
{
temp[i] = arr[highind];
i++;
highind++;
}
for(i=low;i<=high;i++)
arr[i] = temp[i-low];
}
void divider(int low,int high)
{
int mid = (low+high)/2;
if(low<mid)
{
divider(low,mid);
divider(mid+1,high);
merge(low,mid,high);
}
}
int main()
{
int i,j,temp;
for(i=0;i<20;i++)
arr[i] = rand()%21;
for(i=0;i<20;i++)
printf("%d ",arr[i]);
printf("\n");
divider(0,19);
for(i=0;i<20;i++)
printf("%d ",arr[i]);
printf("\n");
return 0;
}