高速分拣
2015-09-16 16:34
239 查看
#include<iostream> #include<iterator> #include<vector> #include<algorithm> #include<time.h> using namespace std; /* *高速排序问题 */ void Fast_sort(vector<int>& a,int beg,int end) { if(beg+1>=end) return; int key = beg; for (int i = beg , j = end; i < j; ) { if(key == i) { do { j--; } while (a[j]>a[key]); key = j; }else { do { i++; } while (a[i]<a[key]); key = i; } swap(a[i],a[j]); } Fast_sort(a,beg,key); Fast_sort(a,key+1,end); } int main() { long start, end; vector<int> vec; copy(istream_iterator<int>(cin),istream_iterator<int>(),back_inserter(vec)); start = clock(); Fast_sort(vec,0,vec.size()); end = clock(); copy(vec.begin(),vec.end(),ostream_iterator<int>(cout," ")); cout<<endl; cout <<"程序执行时间(单位:毫秒): "<< end-start <<endl; }
相关文章推荐
- dnsmasq possible DNS-rebind attack detected错误
- Python改回之前版本的方法
- Docker使用
- VS2012(X64)+PCL1.7.2+Kinect SDK1.8+OpenCV2.4
- 从最大似然到EM算法浅解
- Linux线程简单介绍
- 【Tomcat】eclipse运行Bootstrap启动tomcat,免插件配置
- LeetCode 226----Invert Binary Tree
- Session的生命周期
- 如何使用集成了ESP8266芯片的NodeMCU以配置一个可交互的TCP服务器?
- asp.net自定义控件之加载层
- 查询某个字段不在查询结果中的记录
- jsp初体验
- 系统安装SQL Sever2000后1433端口未开放,如何打开1433端口的解决方法
- setImageResource和setImageDrawable区别
- SpringMVC+MyBatis - 12 spring mvc4返回的json日期为Long的解决方案
- HDU 2896 病毒侵袭(AC自动机)
- 精妙的单片机非阻塞延时程序设计
- 华为机试和尚挑水
- org.dom4j.DocumentException: null Nested exception: null解决方法