Advertisement
PonaFly

Untitled

May 28th, 2017
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.09 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4. void sort(int *ar1,int len1,int *ar2,int len2){       //  len1>=len2 => ar1>=ar2
  5.   int len3=(len1+len2);
  6.   int i,j,k=0;
  7.   int *ar3;
  8.   ar3 = (int *) malloc(len3 * sizeof(int));
  9.   while ((i+j)<len3){
  10.    if (j==len2){
  11.      ar3[k]=ar1[i];
  12.      k++;
  13.      i++;
  14.    }
  15.    else {
  16.     if (i==len1){
  17.         ar3[k]=ar1[j];
  18.         j++;
  19.         k++;
  20.     }
  21.     else {
  22.      if (ar1[i]>ar2[j]){
  23.             ar3[k]=ar1[i];
  24.             k++;
  25.             i++;
  26.      }
  27.     else {
  28.      ar3[k]=ar2[j];
  29.      k++;
  30.      j++;
  31.     }
  32.     }
  33.    }
  34.  }
  35. for (i=0;i<len3;i++){
  36.  printf("%d",ar3[i]);
  37.  printf("\n");
  38. }
  39. }
  40.  
  41. int main(){
  42.  int len1,len2,*ar1,*ar2;
  43.  int i=0;
  44.  printf("Write len of ar#1=");
  45.  scanf("%d",&len1);
  46.  printf("Write len of ar#2=");
  47.  scanf("%d",&len2);
  48.  
  49.  ar1 = (int *) malloc(len1 * sizeof(int));
  50.  ar2 = (int *) malloc(len2 * sizeof(int));
  51.  
  52.  while (i<len1){
  53.    scanf("%d",&ar1[i]);
  54.    i++;
  55.  }
  56.  i=0;
  57.  while (i<len2){
  58.    scanf("%d",&ar2[i]);
  59.    i++;
  60.  }
  61.  if (len1>len2) sort(ar1,len1,ar2,len2);
  62.   else sort(ar2,len2,ar1,len1);
  63.   return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement