码迷,mamicode.com
首页 > 编程语言 > 详细

排序--气泡排序

时间:2015-06-18 13:35:48      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:

#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平方)

所以这种排序存在者不确定性,通常情况效率不高。

排序--气泡排序

标签:

原文地址:http://blog.csdn.net/zr1076311296/article/details/46546751

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!