Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template <class ForwardIt>
- void qSort(ForwardIt first, ForwardIt last) {
- ThreadPool threadPool(thread::hardware_concurrency());
- qSortAuxiliary(first, last, threadPool);
- }
- template <class ForwardIt>
- void qSortAuxiliary(ForwardIt first, ForwardIt last, ThreadPool & threadPool) {
- typedef iterator_traits<ForwardIt>::value_type T;
- while (true) {
- if(first == last) return;
- auto pivot = first;
- advance(pivot, distance(first, last) / 2);
- auto middle1 = std::partition(first, last, [pivot](const T& em){ return em < *pivot; });
- auto middle2 = std::partition(middle1, last, [pivot](const T& em){ return !(*pivot < em); });
- threadPool.appendFn(bind(qSortAuxiliary<ForwardIt>, middle2, last, std::ref(threadPool)));
- last = middle1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement