26void quicksort(It1 first1, It1 last1, It2 first2, Comparator compare)
28 using T1 =
typename std::iterator_traits<It1>::value_type;
29 using T2 =
typename std::iterator_traits<It2>::value_type;
31 std::vector<std::pair<T1, T2>> data;
32 data.reserve(std::distance(first1, last1));
33 std::transform(first1, last1, first2, std::back_inserter(data),
34 [](T1
const& t1, T2
const& t2)
35 {
return std::make_pair(t1, t2); });
38 std::sort(begin(data), end(data), compare);
41 for (
auto const& pair : data)
44 *first2 = pair.second;
72void quicksort(std::vector<T1>& array, std::size_t beg, std::size_t end,
73 std::vector<T2>& perm)
76 assert(end <= array.size());
77 assert(perm.size() == array.size());
79 quicksort(array.data(), beg, end, perm.data());
83void quicksort(std::vector<T1*>& array, std::size_t beg, std::size_t end,
84 std::vector<T2>& perm)
87 assert(end <= array.size());
88 assert(perm.size() == array.size());
91 std::vector<std::pair<T1*, T2>> data;
92 data.reserve(end - beg);
93 std::transform(array.begin() + beg, array.begin() + end, perm.begin() + beg,
94 std::back_inserter(data),
95 [](T1*
const& t1, T2
const& t2)
96 { return std::make_pair(t1, t2); });
99 std::sort(data.begin(), data.end(),
100 [](std::pair<T1*, T2>
const& a, std::pair<T1*, T2>
const& b)
101 { return (*a.first < *b.first); });
104 for (std::size_t i = 0; i < data.size(); i++)
106 array[beg + i] = data[i].first;
107 perm[beg + i] = data[i].second;