#include <stdio.h>
#include <stdlib.h>
void interclas(int *a, int n, int *b, int m, int *c)
{
int i=0,j=0,k=0;
while(i<n && j<m)//cattimp mai sunt elemente in ambele tablouri
if(*(a+i)<*(b+j))
{
*(c+k)=*(a+i);//pun din a in c
i++;//avansez in a
k++;//avansez in c
}
else
{
*(c+k)=*(b+j);
j++;
k++;
}
while(i<n)//au mai ramans elemente in a
{
*(c+k)=*(a+i);
i++;
k++;
}
while(j<m)//au mai ramas elemente in b
{
*(c+k)=*(b+j);
j++;
k++;
}
}
int main()
{
int i,n,m,k,*a,*b,*c;
printf("n=");scanf("%d",&n);
a=(int *)malloc(n*sizeof(int));
for(i=0;i<n;i++)
scanf("%d",&*(a+i));
printf("m=");scanf("%d",&m);
b=(int *)malloc(m*sizeof(int));
for(i=0;i<m;i++)
scanf("%d",&*(b+i));
c=(int *)malloc((m+n)*sizeof(int));
interclas(a,n,b,m,c);
k=n+m;
for(i=0;i<k;i++)
printf("%d ",*(c+i));
return 0;
}
|