使用future的并行快速排序
来源:互联网 发布:网络视频广告案例分析 编辑:程序博客网 时间:2024/06/05 10:46
#include<iostream>#include<list>#include<algorithm>#include<iterator>#include<future>/* 非现场版本,使用函数式编程template<typename T>std::list<T> sequential_quick_sort(std::list<T> input){if (input.empty()){return input;}std::list<T> result;result.splice(result.begin(), input, input.begin());T const& pivot = *result.begin();auto divide_point = std::partition(input.begin(), input.end(),[&](T const& t){return t<pivot; });std::list<T> lower_part;lower_part.splice(lower_part.end(), input, input.begin(),divide_point);auto new_lower(sequential_quick_sort(std::move(lower_part)));auto new_higher(sequential_quick_sort(std::move(input)));result.splice(result.end(), new_higher);//Using synchronization of operations to simplify coderesult.splice(result.begin(), new_lower);return result;}*////并行版本template<typename T>std::list<T> parallel_quick_sort(std::list<T> input){if (input.empty()){return input;}std::list<T> result;result.splice(result.begin(), input, input.begin());T const& pivot = *result.begin();auto divide_point = std::partition(input.begin(), input.end(),[&](T const& t){return t<pivot; });std::list<T> lower_part;lower_part.splice(lower_part.end(), input, input.begin(),divide_point);std::future<std::list<T> > new_lower(std::async(¶llel_quick_sort<T>, std::move(lower_part)));auto new_higher(parallel_quick_sort(std::move(input)));result.splice(result.end(), new_higher);result.splice(result.begin(), new_lower.get());return result;}int main(){std::list<int> input={ 5, 7, 3, 4, 1, 9, 2, 8, 10, 6 };std::list<int>result;result = parallel_quick_sort<int>(input);std::list<int>::iterator i;for (i = result.begin(); i != result.end(); ++i)std::cout << *i << std::endl;}
0 0
- 使用future的并行快速排序
- 并行快速排序
- 并行快速排序
- Erlang 并行快速排序
- go语言写的并行排序算法(快速排序)
- erlang 实现并行快速排序
- 快速排序java并行实现
- callable&future的使用
- Future的使用
- Future的使用
- Future的使用
- java Future的使用
- 并行-Future模式
- 用Parallel_For进行并行快速排序
- 利用OpenMP实现并行快速排序算法
- OpenMP: OpenMP并行快速排序算法
- 通过Callable,Future实现十亿数据的并行相加
- 快速排序qsort的使用
- 怎样玩转千万级别的数据
- 解决Setting property 'source' to 'org.eclipse.jst.jee.server的问题
- Android网络缓存
- Java技术笔记1:类与对象实例之系统常用类
- SpringMVC分页前台和控制器
- 使用future的并行快速排序
- HTTPS简介
- Execution和ProcessInstance的区别
- 广义表的head与tail的基本用法
- Java中的面试题-继承与类加载
- 作为一个新手程序员该如何成长?
- String.intern()
- ESP8266使用详解
- 欢迎使用CSDN-markdown编辑器