Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cstdlib>
- const int maxsize = 1000;
- int *interleave(int a[], int lena, int b[], int lenb)
- {
- int *re;
- int temp_size = abs(lena-lenb);
- int ti=0;
- if(temp_size>0)
- {
- if(lena>lenb)
- re = interleave(a,lenb-1,b,lenb-1);
- else
- re = interleave(a,lena-1,b,lena-1);
- int s;
- if(lena>lenb)
- {
- s = lenb;
- ti = lenb*2;
- while(s<lena)
- {
- re[ti] = a[s];
- ti++;
- s++;
- }
- }
- else
- {
- s = lena;
- ti = lena*2;
- while(s<lenb)
- {
- re[ti] = b[s];
- ti++;
- s++;
- }
- }
- return re;
- }
- if(lena==0 and lenb==0)
- re = (int*)malloc( maxsize );
- else
- re = interleave(a,lena-1,b,lenb-1);
- re[lena*2] = a[lena];
- re[lenb*2+1] = b[lenb];
- return re;
- }
- int main()
- {
- int la,lb,a[maxsize],b[maxsize];
- scanf("%d",&la);
- for(int i=0;i<la;i++)
- scanf("%d",&a[i]);
- scanf("%d",&lb);
- for(int i=0;i<lb;i++)
- scanf("%d",&b[i]);
- printf("Interleave\n");
- int *result = interleave(a,la,b,lb);
- int max = la+lb;
- for(int i=0;i<max;i++)
- printf("%d ",result[i]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement