내가 만든 merge sort

by gimmepoint posted May 17, 2018
?

단축키

Prev이전 문서

Next다음 문서

ESC닫기

크게 작게 위로 아래로 댓글로 가기 인쇄
Extra Form

void merge(int low,int mid,int high,int a[])
{
    int l1=low,l2=mid+1,i,j,b[max+1]={},end=0;
 
    printf("\nmerge start\nl1 = %d l2 = %d low = %d mid = %d high = %d\n",l1,l2,low,mid,high);
 
    for(i=low;end==0;i++) ///confused
    {
        printf("\nrunning for\ni = %d l1 = %d l2 = %d low = %d mid = %d high = %d\nb = ",i,l1,l2,low,mid,high);
 
        if(a[l1]>=a[l2])
            b[i]=a[l2++];
        else
            b[i]=a[l1++];
 
        end!=(l1<=mid)&&(l2<=high);
        //if(l1==l2)
        //    b[max]=a[l1];
 
        for(j=0;j<max+1;j++)
            printf("%d ",b[j]);
        printf("\na = ");
        for(j=0;j<max+1;j++)
            printf("%d ",a[j]);
        printf("\n    ");
 
        for(j=0;j<low*2;j++)
            printf(" ");
        printf("^");
        for(j=low*2;j<high*2-1;j++)
            printf(" ");
        printf("^\n");/**/
    }
 
 
 
    while(l1<=mid)
        b[i++]=a[l1++];
    while(l2<=high)
        b[i++]=a[l1++];
    printf("1\n");
    for(i=low;i<=high;i++)
        a[i]=b[i];
 
    printf("\nending merge\na = ");
    for(i=0;i<max+1;i++)
            printf("%d ",a[i]);
            printf("\n");/**/
}
 
void sort(int low,int high,int a[])
{
    if(low<high)
    {
        int mid=(low+high)/2;
        sort(low,mid,a);
        sort(mid+1,high,a);
        merge(low,mid,high,a);
    }
    else
        return;
}


아...... 힘들었다