Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template <class T,class comp>
- T mediana (const T &a,const T &b,const T &c, comp cmp)
- {
- if (cmp(a,b)) //a<b
- {
- if (cmp(b,c)) // a<b<c
- return b;
- else //b=max
- return (cmp(a,c))?c:a;
- } else//b<a
- {
- if (cmp(a,c)) // b<a<c
- return a;
- else //a=max
- return (cmp(b,c))?c:b;
- }
- }
- template <class iterator,class comp>
- void par_sort(iterator begin, iterator end, comp cmp)
- {
- int a= end-begin;
- if (end-begin<1000)
- {
- sort(begin, end, cmp);
- }
- else
- {
- iterator::value_type el_dzielacy = mediana(*(begin + ((end-begin)/2)),*begin,*(end-1),cmp);
- iterator podzial = partition(begin, end, [=](const iterator::value_type &a ){return cmp(a,el_dzielacy);} ) ;
- int aa=end-podzial;
- int bb= podzial-begin;
- if (aa==0 || bb==0)
- {
- sort(begin,end);
- return;
- }
- #pragma omp parallel sections
- {
- #pragma omp section
- par_sort( podzial, end, cmp);
- #pragma omp section
- par_sort( begin, podzial, cmp);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement