TheAlgorithms/C++
1.0.0
All the algorithms implemented in C++
Toggle main menu visibility
Main Page
Related Pages
Topics
Namespaces
Namespace List
Namespace Members
All
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
z
Functions
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
z
Variables
Typedefs
Classes
Class List
Class Index
Class Hierarchy
Class Members
All
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
~
Functions
_
a
b
c
d
e
f
g
h
i
k
l
m
n
o
p
q
r
s
t
u
v
w
~
Variables
_
a
b
c
d
e
f
g
h
i
k
l
m
n
p
q
r
s
t
u
v
w
x
y
Typedefs
Related Symbols
Files
File List
File Members
All
_
a
b
c
d
e
f
g
h
i
j
l
m
n
o
p
q
r
s
t
u
w
z
Functions
_
a
b
c
d
e
f
g
h
i
j
l
m
n
o
p
q
r
s
t
u
z
Variables
Typedefs
Macros
Examples
▼
TheAlgorithms/C++
►
The Algorithms - C++
►
Contributor Covenant Code of Conduct
►
Code style convention
►
CONTRIBUTION GUIDELINES
►
Backtracking
Prime factorization
Guidelines for reviewers and maintainers
Todo List
►
Topics
►
Namespaces
►
Classes
▼
Files
▼
File List
►
backtracking
►
bit_manipulation
►
ciphers
►
cpu_scheduling_algorithms
►
data_structures
►
divide_and_conquer
►
dynamic_programming
►
games
►
geometry
►
graph
►
graphics
►
greedy_algorithms
►
hashing
►
machine_learning
►
math
►
numerical_methods
►
operations_on_datastructures
►
others
►
physics
►
probability
►
range_queries
►
scripts
►
search
▼
sorting
bead_sort.cpp
►
binary_insertion_sort.cpp
bitonic_sort.cpp
►
bogo_sort.cpp
►
bubble_sort.cpp
bucket_sort.cpp
cocktail_selection_sort.cpp
►
comb_sort.cpp
►
count_inversions.cpp
counting_sort.cpp
counting_sort_string.cpp
►
cycle_sort.cpp
►
dnf_sort.cpp
►
gnome_sort.cpp
►
heap_sort.cpp
►
insertion_sort.cpp
►
insertion_sort_recursive.cpp
library_sort.cpp
►
merge_insertion_sort.cpp
►
merge_sort.cpp
►
non_recursive_merge_sort.cpp
numeric_string_sort.cpp
odd_even_sort.cpp
►
pancake_sort.cpp
►
pigeonhole_sort.cpp
►
quick_sort.cpp
►
quick_sort_3.cpp
►
quick_sort_iterative.cpp
radix_sort.cpp
►
radix_sort2.cpp
►
random_pivot_quick_sort.cpp
►
recursive_bubble_sort.cpp
selection_sort_iterative.cpp
►
selection_sort_recursive.cpp
shell_sort.cpp
►
shell_sort2.cpp
slow_sort.cpp
►
stooge_sort.cpp
►
strand_sort.cpp
swap_sort.cpp
tim_sort.cpp
►
wave_sort.cpp
►
wiggle_sort.cpp
►
strings
►
File Members
►
Examples
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Friends
Macros
Modules
Pages
Loading...
Searching...
No Matches
radix_sort.cpp
1
#include <cmath>
2
#include <cstdlib>
3
#include <cstring>
4
#include <iostream>
5
6
void
radixsort(
int
a[],
int
n) {
7
int
count[10];
8
int
* output =
new
int
[n];
9
memset(output, 0, n *
sizeof
(*output));
10
memset(count, 0,
sizeof
(count));
11
int
max = 0;
12
for
(
int
i = 0; i < n; ++i) {
13
if
(a[i] > max) {
14
max = a[i];
15
}
16
}
17
int
maxdigits = 0;
18
while
(max) {
19
maxdigits++;
20
max /= 10;
21
}
22
for
(
int
j = 0; j < maxdigits; j++) {
23
for
(
int
i = 0; i < n; i++) {
24
int
t = std::pow(10, j);
25
count[(a[i] % (10 * t)) / t]++;
26
}
27
int
k
= 0;
28
for
(
int
p = 0; p < 10; p++) {
29
for
(
int
i = 0; i < n; i++) {
30
int
t = std::pow(10, j);
31
if
((a[i] % (10 * t)) / t == p) {
32
output[
k
] = a[i];
33
k
++;
34
}
35
}
36
}
37
memset(count, 0,
sizeof
(count));
38
for
(
int
i = 0; i < n; ++i) {
39
a[i] = output[i];
40
}
41
}
42
delete
[] output;
43
}
44
45
void
print(
int
a[],
int
n) {
46
for
(
int
i = 0; i < n; ++i) {
47
std::cout << a[i] <<
" "
;
48
}
49
std::cout << std::endl;
50
}
51
52
int
main
(
int
argc,
char
const
* argv[]) {
53
int
a[] = {170, 45, 75, 90, 802, 24, 2, 66};
54
int
n =
sizeof
(a) /
sizeof
(a[0]);
55
radixsort(a, n);
56
print(a, n);
57
return
0;
58
}
numerical_methods::simpson_method::k
double k(double x)
Another test function.
Definition
composite_simpson_rule.cpp:117
main
int main()
Main function.
Definition
generate_parentheses.cpp:110
sorting
radix_sort.cpp
Generated by
1.12.0