#include
void sort(int a[],int n)
{
int i,j,t;
for(i=0;ifor(j=0;j if(a[j]>a[j+1])
{
t = a[j];
a[j] = a[j+1];
a[j+1] = t;
}
}
void merge(int c[],int a[],int len1,int b[],int len2)
{
int i=0,j=0,len=0;
while(i{
if(a[i] else c[len++] = b[j++];
}
while(iwhile(j }
void print(int c[],int len)
{
int i;
for(i=0;iprintf("%d ",c[i]);
printf("\n");
}
int main()
{
int a[]={3,2,1,8,9};
int b[]={3,4,1,3,4,20,10};
int c[100],lena,lenb,lenc;
lena = sizeof(a)/sizeof(a[0]);
lenb = sizeof(b)/sizeof(b[0]);
sort(a,lena);
sort(b,lenb);
merge(c,a,lena,b,lenb);
lenc = lena + lenb;
print(c,lenc);
return 0;
}
归并排序么不是,网上有代码参考的~