麻烦大家帮忙看看这个合并排序程序哪里错了
程序可以运行,但是结果不正确,弄了很久都不知道哪里错了,求助下大家。。谢谢程序代码:
#include <stdio.h> int a[]={78,15,24,16,89,135,4,66}; int b[8]; void merge1(int low,int mid,int high) { int i=low,j=mid+1; int k=0; while (i < mid && j < high) if (a[i]<a[j]) b[k++]=a[i++]; else b[k++]=a[j++]; while (i<mid) b[k++]=a[i++]; while (j<high) b[k++]=a[j++]; } void sort1(int low,int high) { if(low<high) { int mid=(low+high)/2; printf("sort (%d-%d, %d-%d) %d %d %d %d %d %d %d %d\n", low, mid, mid+1, high, b[0],b[1], b[2], b[3], b[4], b[5], b[6], b[7]); sort1(low,mid); sort1(mid+1,high); merge1(low,mid,high); printf("merge (%d-%d, %d-%d) to %d %d %d %d %d %d %d %d\n", low, mid, mid+1, high, b[0], b[1], b[2], b[3], b[4], b[5], b[6], b[7]); } } void main() { sort1(0,7); }