Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- void sort(int *ar1,int len1,int *ar2,int len2){ // len1>=len2 => ar1>=ar2
- int len3=(len1+len2);
- int i,j,k=0;
- int *ar3;
- ar3 = (int *) malloc(len3 * sizeof(int));
- while ((i+j)<len3){
- if (j==len2){
- ar3[k]=ar1[i];
- k++;
- i++;
- }
- else {
- if (i==len1){
- ar3[k]=ar1[j];
- j++;
- k++;
- }
- else {
- if (ar1[i]>ar2[j]){
- ar3[k]=ar1[i];
- k++;
- i++;
- }
- else {
- ar3[k]=ar2[j];
- k++;
- j++;
- }
- }
- }
- }
- for (i=0;i<len3;i++){
- printf("%d",ar3[i]);
- printf("\n");
- }
- }
- int main(){
- int len1,len2,*ar1,*ar2;
- int i=0;
- printf("Write len of ar#1=");
- scanf("%d",&len1);
- printf("Write len of ar#2=");
- scanf("%d",&len2);
- ar1 = (int *) malloc(len1 * sizeof(int));
- ar2 = (int *) malloc(len2 * sizeof(int));
- while (i<len1){
- scanf("%d",&ar1[i]);
- i++;
- }
- i=0;
- while (i<len2){
- scanf("%d",&ar2[i]);
- i++;
- }
- if (len1>len2) sort(ar1,len1,ar2,len2);
- else sort(ar2,len2,ar1,len1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement