冒泡排序
#include<iostream>
using namespace std;
int main()
{
int array[9] = { 2,1,4,6,5,9,7,3,8 };
cout << "排序前数组为" << endl;
for (int i = 0; i < 9; i++)
{
cout << array[i] <<" ";
}
cout << endl;
for (int i = 0; i < 9-1; i++)
{
for (int j = 0; j<9 - i - 1;j++)
{
if (array[j] > array[j + 1])
{
int temp = array[j];
array[j] = array[j + 1];
array[j+1] = temp;
}
}
}
cout << "排序后数组为" << endl;
for (int i = 0; i <9; i++)
{
cout << array[i] <<" ";
}
cout << endl;
system("pause");
return 0;
}