bubble sort 程式問題
想請問各位如何把程式排序的過程都顯示出來還有如何讓他橫向排列,我的是直的
#include <iostream>
using namespace std;
int main()
{
int x={18,2,20,34,12};
int i,j;
for(i=0;i<5;i++){
cout << x << endl;
}
for(i=0;i<4;i++){
for(j=0;j<4-i;j++){
if(x>x){
int x1 = x;
x = x;
x = x1;
}
}
}
for(i=0;i<5;i++){
cout << x << endl;
}
return 0;
}
感謝各位 #include <iostream>
using namespace std;
int main()
{
int x={18,2,20,34,12};
int i,j;
for(i=0;i<5;i++){
cout << x << " ";
}
cout << endl << endl;
for(i=0;i<4;i++){
for(j=0;j<4-i;j++){
if(x>x){
cout << "交换:" << x << "" << x << endl;
int x1 = x;
x = x;
x = x1;
continue;
}
cout << "保持不变:" << x << endl;
}
cout << "交换后为:" ;
for(int k=0; k<5; k++)
{
cout << x << " ";
}
cout << endl;
cout << "-------------第"<< i+1 <<"轮交换结束---------------"<< endl;
}
cout << endl << endl;
for(i=0;i<5;i++){
cout << x << " ";
}
cout << endl << endl;
return 0;
}
页:
[1]