#include <iostream>
using namespace std;
void Show(int* pList, int nCount)
{
for (int nIndex = 0; nIndex < nCount; nIndex++)
cout << pList[nIndex] << "\t";
cout << endl;
}
void BubbleSort_base(int* pList,int nCount)//冒泡排序基本版
{
for (int n = 1; n <= nCount - 1; n++)
{
for (int m = 1; m <= nCount - 1; m++)
{
if (pList[m - 1] > pList[m])
{
int nSave = pList[m - 1];
pList[m - 1] = pList[m];
pList[m] = nSave;
}
}
}
}
void bubbleSort_pro(int* pList,int nCount)//冒泡排序升级版
{
bool bSwap = true;//是否发生交换
int nIndex = nCount - 1;
while (bSwap)
{
bSwap = false;
for (int nMove = 1; nMove <= nIndex; nMove++)
{
if (pList[nMove - 1] > pList[nMove])
{
int nSave = pList[nMove - 1];
pList[nMove - 1] = pList[nMove];
pList[nMove] = nSave;
bSwap = true;
}
}
nIndex--;
}
}
int main(int argc, char* argv[], char* enp[])
{
int pList[] = {15,64,85,59,47,95,46,35,77,80};
int nCount = sizeof(pList) / sizeof(int);
bubbleSort_pro(pList, nCount);
Show(pList, nCount);
getchar();
return 0;
}