#include< iostream.h >
int p(int,int);
int n=10, ar[100],temp[100];
void main(){
int i;
cout<<"10개의 수를 입력하여 주세요"<<endl;
for(i=0;i<n;i++){
cin>>ar[i];
}
cout << "단계"<<endl;
p(0, n-1);
for(i=0;i<n;i++){
// cout<<ar[i]<<" ";
}
cout<<endl;
}
int p(int a, int b){
int i, j,c;
if(b-a>1){
p(a,(a+b)/2);
p((a+b)/2+1,b);
}
for(i=a;i<=b;i++){
// cout<<ar[i]<<" ";
}
i=c=a;
j=(a+b)/2 + 1;
cout<<endl;
while(i<=(a+b)/2 && j <= b){
if(ar[i]<ar[j]) temp[c++]=ar[i++];
else temp[c++]=ar[j++];
}
while(i<=(a+b)/2)
{
temp[c++]=ar[i++];
}
while(j<=b)
{
temp[c++]=ar[j++];
}
//for(i=a;i<=b;i++){
for(i=0;i<10;i++){
cout<<ar[i]<<" ";
}
cout<<endl;
for(i=a;i<=b;i++) ar[i]=temp[i];
return 0;
}
댓글 영역