the improved BubbleSort.
来源:互联网 发布:unity 2d 不会编程 编辑:程序博客网 时间:2024/06/14 20:39
the bubble sort is easy to use,but the effiency is pretty low.How we solve the problem?
when we use bubble sort,we know when we sort the data again and again,it seems that there is a status that the sort has already sorted,but we also scan the data,so,it is an abuse.In order to make it more efficient,we can use a flag to judge the scanner's status,if the scanner is still working.we continue the process of scan.While the scanner is stop,we can make the flag into 1 status,so we can jump out through the circulation.the method is very famous:more space instead of time.the following is the realization.
void bubblesort(int a[],int n)
{
int i,j,flag=0,r;
for(i=0;i<n-1;i++)
{
for(j=n-1;j>i;j--)
{
if(a[j]<a[j-1])
{
r=a[j-1];
a[j-1]=a[j];
a[j]=r;
flag = 1;//there has the exchange of data
}
}
if(flag = 0)
break;
else
flag = 0;
}
}
- the improved BubbleSort.
- BubbleSort
- BubbleSort
- BubbleSort
- bubblesort
- Bubblesort
- BubbleSort
- BubbleSort
- bubblesort
- bubblesort
- bubbleSort
- BubbleSort
- BubbleSort
- BubbleSort
- bubbleSort
- bubbleSort
- BubbleSort
- BubbleSort
- solrcloud基本知识
- 超级表格漂流记
- 友善6410开发板RS232改RS485(内核驱动修改)
- ehcache集群缓存配置
- Android中ViewPager的简单使用(底部圆点)
- the improved BubbleSort.
- 判断链表是否存在环
- [iPhone高级] 基于XMPP的IOS聊天客户端程序(XMPP服务器架构)
- 文件描述符
- 袁小伟博士“用户研究和产品创新”讲座有感
- SCALA 集合框架文档翻译-Concrete Mutable Collection Classes
- Android Activity 切换动画效果
- tomcat5.5的配置、性能优化
- [iPhone中级] iPhone团购信息客户端的开发 (三)