//Ex4_4.cpp
#include "iostream" 
using namespace std;
#define N 5 
void main() 
{int i,j,t,a[N]={4,8,3,1,5}; 
 cout<<"排序前数据:"; 
 for(i=0;i<N;i++)cout<<a[i]<<" "; 
 for (i=1;i<=N-1;i++) //有N个数需进行N-1趟比较 
	{for (j=0;j<N-i;j++) 
       if(a[j]>a[j+1]) //进行两个相邻元素比较 
		{t=a[j];a[j]=a[j+1];a[j+1]=t;} 
     cout<<"\n 第 "<<i<<" 趟排序 "; 
     for(j=0;j<N;j++)cout<<a[j]<<" "; //显示第i趟排序结果 
	} 
 cout<<"\n排序后结果："; 
 for(j=0;j<N;j++)cout<<a[j]<<" "; 
 cout<<endl; 
}
