Skip to content

Commit a506a36

Browse files
committed
Merge branch 'develop'
2 parents 7291ace + 40143ad commit a506a36

File tree

124 files changed

+650
-590
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

124 files changed

+650
-590
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ MutableValueGraph<City, Distance> roads = ValueGraphBuilder.directed()
227227

228228
**Graph algorithms**
229229

230+
> NOTE: In the following, the C++ implementations are currently only available on MSVC.
231+
230232
- A\* search algorithm, CCSP#2.2.5: A single-pair shortest path algorithm. This is a variant of Dijkstra's algorithm using heuristics to try to speed up the search.
231233
- Bellman-Ford algorithm, CLRS#24.1: [c++](cpp-algorithm/src/cpp-algorithm/src/graph/bellman_ford.h), [java#1](java-algorithm/src/main/java/com/example/algorithm/graph/BellmanFord1.java), [java#2](java-algorithm/src/main/java/com/example/algorithm/graph/BellmanFord2.java) | A single source the shortest path algorithm that can handle negative edge weights. It finds the shortest path from a source vertex to all other vertices in a weighted graph.
232234
@@ -387,6 +389,8 @@ algorithm Prim(G, root):
387389

388390
**Examples**
389391

392+
> NOTE: In the following, the C++ implementations are currently only available on MSVC.
393+
390394
- Maze problem: [java](java-algorithm/src/main/java/com/example/algorithm/graph/MazeProblem.java) | A maze problem is that find a path from the start to the goal. The maze is represented by a graph. The start and the goal are represented by vertices. The path is represented by a sequence of vertices.
391395
- Minimum spanning tree (Kruskal, Prim, Boruvka), CLRS#23, CCSP#4.4.2: [python(test)](python-algorithm/algorithm/graph/test/test_minimum_spanning_tree.py) | Find the minimum spanning tree of a graph. cf. Kruskal(CLRS#23.2, CLRS#21.1), Prim(CLRS#23.2)
392396

cpp-algorithm/src/array/advancing_through.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
auto AdvancingThrough::CanReachEnd(const std::vector<int>& max_advance_steps) -> bool
44
{
5-
auto furthest_reach_so_far = 0;
6-
const auto last_index = static_cast<int>(max_advance_steps.size()) - 1;
5+
int reach_so_far = 0; // furthest reach so far
6+
const int last_index = static_cast<int>(max_advance_steps.size()) - 1;
77

8-
for (int i = 0; i <= furthest_reach_so_far && furthest_reach_so_far < last_index; ++i)
8+
for (int i = 0; i <= reach_so_far && reach_so_far < last_index; ++i)
99
{
10-
furthest_reach_so_far = std::max(furthest_reach_so_far, max_advance_steps[i] + i);
10+
reach_so_far = std::max(reach_so_far, max_advance_steps[i] + i);
1111
}
1212

13-
return furthest_reach_so_far >= last_index;
13+
return reach_so_far >= last_index;
1414
}

cpp-algorithm/src/array/arbitrary_precision_integer.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,22 @@ auto ArbitraryPrecision::PlusOne(std::vector<int> number_array) -> std::vector<i
2020
return number_array;
2121
}
2222

23-
auto ArbitraryPrecision::StringAddition(const std::string& number_string1, const std::string& number_string2) -> std::vector<int>
23+
auto ArbitraryPrecision::StringAddition(const std::string& number_string1,
24+
const std::string& number_string2)
25+
-> std::vector<int>
2426
{
25-
const auto size1 = static_cast<int>(number_string1.size());
26-
const auto size2 = static_cast<int>(number_string2.size());
27+
const int size1 = static_cast<int>(number_string1.size());
28+
const int size2 = static_cast<int>(number_string2.size());
2729

28-
const auto larger = size1 >= size2 ? size1 : size2;
30+
const int larger = size1 >= size2 ? size1 : size2;
2931
auto sum = std::vector<int>(larger);
3032

3133
for (int i = size1 - 1; i >= 0; --i)
3234
{
3335
sum[i] += number_string1.at(i) == '1' ? 1 : 0;
3436
}
3537

36-
auto carry = 0;
38+
int carry = 0;
3739
for (int i = size2 - 1; i >= 0; --i)
3840
{
3941
sum[i] += carry;
@@ -58,9 +60,11 @@ auto ArbitraryPrecision::StringAddition(const std::string& number_string1, const
5860
return sum;
5961
}
6062

61-
auto ArbitraryPrecision::Multiply(std::vector<int>& number_array1, std::vector<int>& number_array2) -> std::vector<int>
63+
auto ArbitraryPrecision::Multiply(std::vector<int>& number_array1,
64+
std::vector<int>& number_array2)
65+
-> std::vector<int>
6266
{
63-
const auto sign = ((number_array1.front() < 0) ^ (number_array2.front() < 0)) ? -1 : 1;
67+
const int sign = ((number_array1.front() < 0) ^ (number_array2.front() < 0)) ? -1 : 1;
6468
number_array1.front() = std::abs(number_array1.front());
6569
number_array2.front() = std::abs(number_array2.front());
6670

@@ -75,7 +79,8 @@ auto ArbitraryPrecision::Multiply(std::vector<int>& number_array1, std::vector<i
7579
}
7680
}
7781

78-
result = {std::ranges::find_if_not(begin(result), end(result), [](const int i) { return i == 0; }), end(result)};
82+
result = {std::ranges::find_if_not(begin(result), end(result), [](const int i) { return i == 0; }),
83+
end(result)};
7984

8085
if (std::empty(result))
8186
{

cpp-algorithm/src/array/benchmark/arbitrary_precision_integer_benchmark.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ BENCHMARK(BM_PlusOne);
1515

1616
static void BM_StringAddition(benchmark::State& state)
1717
{
18-
const auto number1 = std::string{"101"};
19-
const auto number2 = std::string{"101"};
18+
const std::string number1 = "101";
19+
const std::string number2 = "101";
2020
for (auto _ : state)
2121
{
2222
ArbitraryPrecision::StringAddition(number1, number2);

cpp-algorithm/src/array/benchmark/delete_element_benchmark.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ BENCHMARK(BM_DeleteDuplicateElements);
2727
static void BM_DeleteSpecificElements(benchmark::State& state)
2828
{
2929
auto numbers = std::vector<int>{2, 3, 5, 5, 7, 11, 11, 11, 13};
30-
constexpr auto element = 11;
30+
constexpr int element = 11;
3131
for (auto _ : state)
3232
{
3333
DeleteElement::DeleteSpecificElements(numbers, element);

cpp-algorithm/src/array/benchmark/random_data_sampling_benchmark.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
static void BM_OfflineRandomSampling(benchmark::State& state)
66
{
7-
constexpr auto k = 3;
7+
constexpr int k = 3;
88
auto arr = std::vector<int>{3, 7, 5, 11};
99
for (auto _ : state)
1010
{
@@ -16,7 +16,7 @@ BENCHMARK(BM_OfflineRandomSampling);
1616

1717
static void BM_ComputeRandomPermutation(benchmark::State& state)
1818
{
19-
constexpr auto k = 3;
19+
constexpr int k = 3;
2020
for (auto _ : state)
2121
{
2222
RandomDataSampling::ComputeRandomPermutation(k);

cpp-algorithm/src/array/delete_element.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ auto DeleteElement::DeleteDuplicates(std::vector<int>& numbers) -> std::vector<i
99
return {};
1010
}
1111

12-
auto write_index = 1;
12+
int write_index = 1;
1313
for (int i = 1; i < static_cast<int>(numbers.size()); ++i)
1414
{
1515
if (numbers[write_index - 1] != numbers[i])

cpp-algorithm/src/array/dutch_national_flag.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ auto DutchFlag::DutchFlagPartition2(const int pivot_index, std::vector<Color>& a
3434
{
3535
const auto pivot = arr[pivot_index];
3636

37-
auto smaller = 0;
37+
int smaller = 0;
3838
for (int i = 0; i < static_cast<Color>(arr.size()); ++i)
3939
{
4040
if (arr[i] < pivot)
@@ -43,7 +43,7 @@ auto DutchFlag::DutchFlagPartition2(const int pivot_index, std::vector<Color>& a
4343
}
4444
}
4545

46-
auto larger = static_cast<Color>(arr.size()) - 1;
46+
int larger = static_cast<Color>(arr.size()) - 1;
4747
for (int i = static_cast<Color>(arr.size()) - 1; i >= 0; --i)
4848
{
4949
if (arr[i] > pivot)
@@ -59,8 +59,8 @@ auto DutchFlag::DutchFlagPartition3(const int pivot_index, std::vector<Color>& a
5959
{
6060
const auto pivot = arr[pivot_index];
6161

62-
auto smaller = 0;
63-
auto equal = 0;
62+
int smaller = 0;
63+
int equal = 0;
6464
int larger = static_cast<Color>(arr.size());
6565

6666
while (equal < larger)

cpp-algorithm/src/array/enumerate_prime_number.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#include <deque>
44

5-
auto EnumeratePrime::GeneratePrimes(int n) -> std::vector<int>
5+
auto EnumeratePrime::GeneratePrimes(const int n) -> std::vector<int>
66
{
77
std::vector<int> primes;
88
std::deque<bool> is_prime(n + 1, true);

cpp-algorithm/src/array/enumerate_prime_number.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
namespace EnumeratePrime
77
{
88
/**
9-
* brief Enumerate prime numbers in the range.
10-
* param n upper bound
11-
* return prime numbers
9+
* \brief Enumerate prime numbers in the range.
10+
* \param n upper bound
11+
* \return prime numbers
1212
*/
1313
auto GeneratePrimes(int n) -> std::vector<int>;
1414
}

0 commit comments

Comments
 (0)