Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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;
- }
Add Comment
Please, Sign In to add comment