现在的位置: 首页 > 综合 > 正文

冒泡排序

2014年01月04日 ⁄ 综合 ⁄ 共 227字 ⁄ 字号 评论关闭
#include<iostream>
using namespace std;
int main()
{
	int temp=0;
	int a[]={1,5,6,3,4,7,8,6,3};
	for(int i=0;i<9;i++)
		for(int j=0;j<9;j++)
			if(a[j]>a[j+1])
			{
				temp=a[j];
				a[j]=a[j+1];
				a[j+1]=temp;
			}
	for(i=0;i<9;i++)
		cout<<a[i]<<" ";
	return 0;
}

 平均代码复杂度为O(n^2)

抱歉!评论已关闭.