Guest User

Untitled

a guest
Feb 24th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. int s3(int *a,int s2,int e1,int s1,int e2,int* m1,int* m2);
  2.  
  3. int s4(int* a,int l){
  4. int s=0, *m1=(int *)malloc(l*sizeof(int)), *m2=(int *)malloc(l*sizeof(int));
  5. if(!m1&&!m2)return -1;
  6. while (s<l) {
  7. int i,s1,e1,s2,e2;
  8. for(i=0;(i+s-1)<(l-1);i+=2*s){
  9. s1=i;
  10. e1=i+s-1;
  11. s2=e1+1;
  12. (i+2*s-1)<(l-1)?(e2=i+2*s-1):(e2=l-1);
  13. s3(a,s1,e1,s2,e2,m1,m2);
  14. }
  15. s=s<<1;
  16. }
  17. return 0;
  18. }
  19.  
  20. int s3(int *a,int s1,int e2,int s2,int e1,int* m1,int* m2){
  21. int l1=e1-s1+1, ll=e2-s2+1, p1=0, p2=0, p=s1;
  22. for(unsigned i = 0; i < l1; ++i) m1[i] = (a+s1)[i];
  23. for(unsigned i = 0; i < ll; ++i) m2[i] = (a+s1)[i];
  24. while (p1<l1&&p1<ll) if(m1[p1]<m2[p2])a[p++]=m1[p1++]; else a[p++]=m2[p2++];
  25. while (p1<l1) a[p++]=m1[p1++];
  26. while(p2<ll) a[p++]=m2[p2++];
  27. return 0;
  28. }
  29.  
  30. int main(){
  31. int a[10]={8,9,20,0,3,20,0};
  32. int l=10;
  33. s4(a,l);
  34.  
  35. int i;
  36. for (i=0;i<l;i++)printf("%d\t",a[i]);
  37. printf("\n");
  38. return 0;
  39. }
Add Comment
Please, Sign In to add comment