// BubbleSort.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
void swap(int& a,int& b)
{
if(&a==&b)
return;
int tmp=a;
a=b;
b=tmp;
}
void BubbleSort(int *a,int n)
{
int i,j;
int flag;
for(i=0;i<n-1;i++)
{
flag=0;
for(j=n-1;j>i;j--)
{
if(a[j]<a[j-1])
{
swap(a[j],a[j-1]);
flag=1;
}
}
if(0==flag)
break;
}
}
void main()
{
int r[9]={565,10,3,5,1,9,34,54,0};
for(int q=0;q<9;q++)
printf(" %d",r[q]);//cout<<" "<<r[q];
printf("\n");//cout<<"\n";
BubbleSort(r,9);
for( q=0;q<9;q++)
printf(" %d",r[q]);//cout<<" "<<r[q];
printf("\n");//cout<<"\n";
}