#include<iostream>
using namespace std;
#define SIZE 21
typedef int Sqlist[SIZE];
void QipaoSort(Sqlist &L,int n)
{
int i,j;
for(i = 1;i<n-1;++i)
{
for(j = 1;j<n-i;++j)
{
if(L[j] > L[j+1])
{
L[0] = L[j];
L[j] = L[j+1];
L[j+1] = L[0];
}
}
}
}
void main()
{
Sqlist L= {0,49,38,65,97,76,13,27};
QipaoSort(L,8);
for(int i=1;i<8;++i)
cout<<L[i]<<" ";
cout<<endl;
}
分析:气泡排序优缺点如下:
1.最好情形:时间复杂度为O(n)
2.最坏情性:时间复杂度为O(n平方)
所以这种排序存在者不确定性,通常情况效率不高。