#include <iostream>
#include <algorithm>
using namespace std;
void BulldingSort(int* a,int length)
{
int nCount = 0;
if(a != NULL && length > 0)
{
bool bChanged = false;
int i = 0;
for(i = 0;i < length - 1;i++)
{
for(int j = 0 ;j < length - i - 1;j++)
{
if(a[j + 1] < a[j])
{
int nTemp = a[j];
a[j] = a[j+1];
a[j+1] = nTemp;
bChanged = true;
}
nCount++;
}
if(!bChanged)
{
break;
}
}
std:: cout <<"loop count:" << nCount << std::endl;
}
}
int main()
{
int a[] ={0,1,2,65,54,20,30,40,20};
int b[] ={0,1,2,3,4,5,6,7,8};
int c[] ={8,7,6,5,4,3,2,1,0};
int lengthA = sizeof(a) / sizeof(a[0]);
int lengthB = sizeof(b) / sizeof(b[0]);
int lengthC = sizeof(c) / sizeof(c[0]);
BulldingSort(a,lengthA);
BulldingSort(b,lengthB);
BulldingSort(c,lengthC);
std::for_each(a,a+lengthA,[](int i){
std::cout << i << std::endl;});
std:: cout << "b:" << std::endl;
std::for_each(b,b+lengthB,[](int i){
std::cout << i << std::endl;});
std:: cout << "c:" << std::endl;
std::for_each(c,c+lengthC,[](int i){
std::cout << i << std::endl;});
return 0;
}