将数组a[9]={4,2,8,0,5,7,1,3,9}利用冒泡排序法进行排序
#include<iostream>
using namespace std;
int main()
{
int temp;
int a[9] = { 4,2,8,0,5,7,1,3,9 };
for (int i = 1; i <= 8; i++)
{
for (int j = 0; j <=9 - i; j++)
{
if (a[j + 1] > a[j])
{
temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
}
}
for (int k = 0; k < 9; k++)
{
cout << a[k] << ' ';
}
cout << endl;
system("pause");
return 0;
}