2 u013966274 u013966274 于 2014.03.12 19:32 提问

哪位大神帮我看看问题出在哪啊??(归并排序)

#include
void Merge(int *a ,int low,int m,int high)

{

int i=low,j=m+1,p=0;
int R[7];
while(i<=m&&j<=high)

{

R[p++]=(a[i]<=a[j])?a[i++]:a[j++];

}

while(i<=m) {                        
    R[p++]=a[i++];  
}  
while(j<=high)                      
{  
    a[p++]=a[j++];  
}  

for(p=0,i=low;i<=high;p++,i++)  
{  
    a[i]=R[p];                      
}  

}

void MergeSort( int *a ,int low,int high)

{

int mid;

if(low<high)

{

mid=(low+high)/2;

MergeSort(a,low,mid);

MergeSort(a,mid+1,high);

Merge(a,low,mid,high);

}

}
int main()

{

void MergeSort( int *a,int low,int high);
int i,oo;
int a[7]={78,485,1235,262,54,61,35};

int low=0,high=6;
printf("Before mergeis sort: ");

for(int i=low;i<=high;i++)

{

printf("%d ",a[i]);

}

printf("\n");

MergeSort(a,low,high);  

printf("After merge sort:  ");  
for( i=low;i<=high;i++)  
{  
    printf("%d ",a[i]);              
}  
printf("\n"); 
scanf("%d",&oo);
return 0;

}

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!