std::vector<uint64_t>& ar) {
55std::vector<uint32_t> position(10, 0);
56 for(
inti = 0; i < n; ++i) {
57position[(ar[i] / cur_digit) %
61 for(
inti = 0; i < 10; ++i) {
66std::vector<uint64_t> temp(n);
67 for(
inti = 0; i < n; ++i) {
68temp[position[(ar[i] / cur_digit) % 10]] =
71position[(ar[i] / cur_digit) %
82std::vector<uint64_t>
radix(
conststd::vector<uint64_t>& ar) {
84*max_element(ar.begin(), ar.end());
85std::vector<uint64_t> temp = ar;
86 for(
inti = 1; max_ele / i > 0;
91 for(uint64_t i : temp) {
92std::cout << i <<
" ";
106std::vector<uint64_t> ar1 = {432, 234, 143, 332, 123};
108assert(std::is_sorted(ar1.begin(), ar1.end()));
110std::vector<uint64_t> ar2 = {213, 3214, 123, 111, 112, 142,
111133, 132, 32, 12, 113};
113assert(std::is_sorted(ar2.begin(), ar2.end()));
Functions for Radix sort algorithm.
static void tests()
Function to test the above algorithm.
std::vector< uint64_t > step_ith(uint16_t cur_digit, const std::vector< uint64_t > &ar)
Function to sort vector according to current digit using stable sorting.
std::vector< uint64_t > radix(const std::vector< uint64_t > &ar)
Function to sort vector digit by digit.
int main()
Main function.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4