//C++实现冒泡排序
#include <iostream>
using namespace std;
void BubbleSort(int* pData, int Count)
{
int Temp;
for (int i = 1; i < Count; i++) //进行Count次排序,Count是要排序的数的个数
{
for (int j = Count - 1; j >= i; j--) //对该轮待排序的数进行排序
{
if (pData[j] < pData[j - 1]) //将大数放在前,小数放在后
{
Temp = pData[j - 1];
pData[j - 1] = pData[j];
pData[j] = Temp;
}
}
}
}
void main()
{
int data[] = {10, 8, 9, 7, 4, 5}; //待排序数组
BubbleSort(data, 6); //对数组进行排序
for (int i = 0; i < 6; i++)
{
cout << data[i] << " ";
}
cout << "\n";
}