默写简单的排序算法
2016-03-15 09:28
357 查看
快速排序: public void sort(int arr[],int low,int high) { int l=low; int h=high; int povit=arr[low]; while(l<h) { while(l<h&&arr[h]>=povit) h--; if(l<h){ int temp=arr[h]; arr[h]=arr[l]; arr[l]=temp; l++; } while(l<h&&arr[l]<=povit) l++; if(l<h){ int temp=arr[h]; arr[h]=arr[l]; arr[l]=temp; h--; } } if(l>low)sort(arr,low,l-1); if(h<high)sort(arr,l+1,high); }
冒泡排序:
public void sort(int[] a)
{
int temp = 0;
for (int i = a.length - 1; i > 0; --i)
{
for (int j = 0; j < i; ++j)
{
if (a[j + 1] < a[j])
{
temp = a[j];
a[j] = a[j + 1];
a[j + 1] = temp;
}
}
}
}
相关文章推荐
- 数学中的常见的距离公式
- (传智播客)四大域对象_读取书籍列表
- Docker 入门到实践笔记1
- [刷题]Implement Stack
- Core Graphics
- 面试感悟
- new (C# Reference)
- 如何应对云爆发架构?四种方法替你解忧
- POJ1703——Find them, Catch them 并查集应用
- PHP设计模式 适配器模式
- 【Boost】boost库asio详解6——boost::asio::error的用法浅析
- 上网调查一下目前流行的源程序版本管理软件和项目管理软件都有哪些?各有什么优缺点?
- iOS CLLocationManager 定位
- 【Boost】boost库asio详解5——resolver与endpoint使用说明
- 用cookie存取变量
- 虚拟机的简单使用
- 详解iOS App开发中UIViewController的loadView方法使用
- javax.el.PropertyNotFoundException: Property 'Name' not found on type com.min.test.User
- 【Boost】boost库asio详解4——deadline_timer使用说明
- 面试题记录