#include
using namespace std;
int a[10001],r[10001];
int n;
int ans;
int ret;
void msort(int s,int t);
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
msort(1,n);
}
void msort(int s,int t)
{
cout<<"第"<<++ans<<"次递归调用之前执行"<<endl;
for(int i=s;i<=t;i++)
cout<<a[i]<<" ";
cout<<endl;
if(s==t) return;
else
{
int mid=(s+t)/2;
msort(s,mid);
msort(mid+1,t);
int i=s,j=mid+1,k=s;
while(i<=mid&&j<=t)
{
if(a[i]<a[j]){ r[k]=a[i];i++;k++;
}
else{r[k]=a[j];j++;k++;
}
}
while(i<=mid)
{
r[k]=a[i];i++;k++;
}
while(j<=t)
{
r[k]=a[j];j++;k++;
}
for(int m=s;m<=t;m++) a[m]=r[m];
cout<<"第"<<++ret<<"次递归返回后执行输出"<<endl;
for(int x=s;x<=t;x++)
cout<<r[x]<<" ";
cout<<endl;
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54