Skip to content

Commit 4c15e77

Browse files
committed
Use std::size_t as type of counter in counting sort
1 parent 83d94a5 commit 4c15e77

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,8 @@
5454
.ionide
5555

5656
*.user
57+
58+
include/benchmark
59+
include/catch2
60+
commands.txt
61+
build

include/sorting_algorithms/sort.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ template <class BidirectionalIterator,
703703
class Int = typename std::iterator_traits<BidirectionalIterator>::value_type,
704704
class = typename std::enable_if<std::is_integral<Int>::value>::type>
705705
inline void counting_sort(BidirectionalIterator first, BidirectionalIterator last, Int max, std::size_t n) {
706-
std::vector<Int> counter(max + 1);
706+
std::vector<std::size_t> counter(max + 1);
707707
for (auto it = first; it != last; ++it) {
708708
++counter[*it];
709709
}
@@ -737,7 +737,7 @@ template <class BidirectionalIterator,
737737
class Int = typename std::iterator_traits<BidirectionalIterator>::value_type,
738738
class = typename std::enable_if<std::is_integral<Int>::value>::type>
739739
inline void counting_sort_digit(BidirectionalIterator first, BidirectionalIterator last, Int exp, std::size_t n) {
740-
std::vector<Int> counter(10);
740+
std::vector<std::size_t> counter(10);
741741
for (auto it = first; it != last; ++it) {
742742
++counter[(*it / exp) % 10];
743743
}

0 commit comments

Comments
 (0)