合并排序算法C++实现代码,运行没有结果,帮忙解决,谢谢
我写的C++合并排序递归算法,编译没有错误,但是就是没有结果,请大家帮忙看看,不胜感激程序代码:
#include<iostream> using namespace std; void Merge(int a[],int b[],int left,int mid,int right){ int k,i,j; k=left; i=left; j=mid+1; while(i<=mid&&j<=right) if(a[i]<=a[j]) b[k++]=a[i++]; else b[k++]=a[j++]; while(i<=mid) b[k++]=a[i++]; while(j<right) b[k++]=a[j++]; for(k=0;k<=right;k++) cout <<b[k]; } void MergeSort(int a[],int left,int right){ int mid,*b; if(left<right){ mid=(left+right)/2; MergeSort(a,left,right); MergeSort(a,mid+1,right); Merge(a,b,left,mid,right); } } int main(){ int i,n,k; int b[100]; int a[100]; cout <<"Please input the number of digits to sort:"; cin >>n; cout <<"Please input the number of sort:"<<endl; for(i=0;i<n;i++) cin >>a[i]; cout <<"The sort number is:"<<endl; MergeSort(a,0,n-1); }