基数排序的优雅实现
标签:实现 pen div family class src end 基数排序 const
明天补充
1 template 2 void radix_sort(It _begin, It _end, Radix _radix, int _pass)
3 {
4 auto begin = _begin;
5 std::vector<:vector>>> temp0(_radix()), temp1(_radix());
6 auto src = &temp0;
7 auto dst = &temp1;
8 for (; begin != _end; ++begin)
9 (*src)[_radix(*begin, 0)].push_back(*begin);
10 for (int pass = 1; pass != _pass; ++pass)
11 {
12 for (auto& v : *dst)
13 v.clear();
14 for (const auto& v: *src)
15 for (const auto& i : v)
16 (*dst)[_radix(i, pass)].push_back(i);
17 std::swap(src, dst);
18 }
19 for (const auto& v : *src)
20 for (const auto& i : v)
21 {
22 *_begin = i;
23 ++_begin;
24 }
25 }
基数排序的优雅实现
标签:实现 pen div family class src end 基数排序 const
原文地址:https://www.cnblogs.com/jerry-fuyi/p/11154757.html
评论