#include
using namespace std;
int a[3];
int b[3];
void mergesort(int low,int high);
int merge(int low ,int high,int mid);
int main()
{
for(int i=0;i<3;i++)
{
cin>>a[i];
}
for(int i=0;i<3;i++)
{
mergesort(i,2);
cout< }
getchar();
getchar();
getchar();
return 0;
}
void mergesort(int low,int high)
{
int mid=(low+high)/2;
mergesort(low,mid);
mergesort(mid+1,high);
merge(low,mid,high);
}
int merge(int low ,int high,int mid)
{
int h=low,i=low,j=mid+1,k;
while((h<=mid)&&(j<=high))
{
if(a[h]<=a[j])
{b[i]=a[h];h++;}
else
{b[i]=a[j];j++;}
i++;
}
if(h>mid)
for(k=j;k {
b[i]=a[k];
i++;
}
else
for(k=h;k<=mid;k++)
{
b[i]=a[k];
i++;
}
for(k=low;ka[k]=b[k];
return a[i];
}
--------------------next---------------------
#include
using namespace std;
int a[3];
int b[3];
void mergesort(int low,int high);
int merge(int low ,int high,int mid);
int main()
{
for(int i=0;i<3;i++)
{
cin>>a[i];
}
for( i=0;i<3;i++)
{
mergesort(i,2);
cout< }
getchar();
getchar();
getchar();
return 0;
}
void mergesort(int low,int high)
{
int mid=(low+high)/2;
mergesort(low,mid);
mergesort(mid+1,high);
merge(low,mid,high);
}
int merge(int low ,int high,int mid)
{
int h=low,i=low,j=mid+1,k;
while((h<=mid)&&(j<=high))
{
if(a[h]<=a[j])
{b[i]=a[h];h++;}
else
{b[i]=a[j];j++;}
i++;
}
if(h>mid)
for(k=j;k {
b[i]=a[k];
i++;
}
else
for(k=h;k<=mid;k++)
{
b[i]=a[k];
i++;
}
for(k=low;ka[k]=b[k];
return a[i];
}
--------------------next---------------------
阅读(996) | 评论(0) | 转发(0) |