# include & ltstdlib.h & gt#定義NA 5
#define NB 5void Sort(int a[],int nLen)
{
for(int I = 0;我& ltnLen-1;i++)
{
int n = I;
int p = a[I];
for(int j = I+1;j & ltnLenj++)
{
if(a[j]& lt;p)
{
p = a[j];
n = j;
}
}
int t = a[I];
a[I]= a[n];
a[n]= t;
}
}int* Merge(int a[],int nLena,int b[],int nLenb)
{
int * c =(int *)malloc((nLena+nLenb)* sizeof(int));
int I = 0;
int j = 0;
int n = 0;
while(我& ltnLena & amp& ampj & ltnLenb)
{
if(a[I]& lt;= b[j])
{
c[n++]= a[i++];
}
其他
{
c[n++]= b[j++];
}
}
如果(我& ltnLena)
{
for(;我& ltnLenai++)
{
c[n++]= a[I];
}
}
if(j & lt;nLenb)
{
for(;j & ltnLenbj++)
{
c[n++]= b[j];
}
}
返回c;
}void main()
{
int a[NA]= { 0 };
int b[NB]= { 0 };
printf("為a[]:",NA輸入%d個數字);
for(int I = 0;我& ltNA;i++)
{
scanf("%d ",& ampa[I]);
}
printf("為b[]:",NB輸入%d個數字);
for(I = 0;我& ltNB;i++)
{
scanf("%d ",& ampb[I]);
}
Sort(a,NA);
Sort(b,NB);
printf("排序後的a[]:);
for(I = 0;我& ltNA;i++)
{
printf("%d ",a[I]);
}
printf("\nb[]在排序: ")之後;
for(I = 0;我& ltNB;i++)
{
printf("%d ",b[I]);
}
int *c = Merge(a,NA,b,NB);
printf(" \ na[]b[]after merge:");
for(I = 0;我& ltNA+NB;i++)
{
printf("%d ",c[I]);
}
printf(" \ n ");
}