Last active
February 13, 2018 06:06
-
-
Save e5l/20b022ce4717489dd36c66ac23e20655 to your computer and use it in GitHub Desktop.
Debug me
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int s3(int *a,int s2,int e1,int s1,int e2,int* m1,int* m2); | |
int s4(int* a,int l){ | |
int s=0, *m1=(int *)malloc(l*sizeof(int)), *m2=(int *)malloc(l*sizeof(int)); | |
if(!m1&&!m2)return -1; | |
while (s<l) { | |
int i,s1,e1,s2,e2; | |
for(i=0;(i+s-1)<(l-1);i+=2*s){ | |
s1=i; | |
e1=i+s-1; | |
s2=e1+1; | |
(i+2*s-1)<(l-1)?(e2=i+2*s-1):(e2=l-1); | |
s3(a,s1,e1,s2,e2,m1,m2); | |
} | |
s=s<<1; | |
} | |
return 0; | |
} | |
int s3(int *a,int s1,int e2,int s2,int e1,int* m1,int* m2){ | |
int l1=e1-s1+1, ll=e2-s2+1, p1=0, p2=0, p=s1; | |
for(unsigned i = 0; i < l1; ++i) m1[i] = (a+s1)[i]; | |
for(unsigned i = 0; i < ll; ++i) m2[i] = (a+s1)[i]; | |
while (p1<l1&&p1<ll) if(m1[p1]<m2[p2])a[p++]=m1[p1++]; else a[p++]=m2[p2++]; | |
while (p1<l1) a[p++]=m1[p1++]; | |
while(p2<ll) a[p++]=m2[p2++]; | |
return 0; | |
} | |
int main(){ | |
int a[10]={8,9,20,0,3,20,0}; | |
int l=10; | |
s4(a,l); | |
int i; | |
for (i=0;i<l;i++)printf("%d\t",a[i]); | |
printf("\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment