Skip to content

Commit 8e329d3

Browse files
fix: include cstdint to fix compilation
1 parent 902e297 commit 8e329d3

File tree

8 files changed

+93
-73
lines changed

8 files changed

+93
-73
lines changed

dynamic_programming/abbreviation.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
*/
2525

2626
#include <cassert> /// for `assert`
27+
#include <cstdint> /// for `std::uint32_t`
2728
#include <iostream> /// for IO operations
2829
#include <string> /// for `std::string` library
2930
#include <vector> /// for `std::vector` STL library

dynamic_programming/cut_rod.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <array>
2222
#include <cassert>
2323
#include <climits>
24+
#include <cstdint>
2425
#include <iostream>
2526
/**
2627
* @namespace dynamic_programming
@@ -70,8 +71,8 @@ int maxProfitByCuttingRod(const std::array<int, T> &price, const uint64_t &n) {
7071
*/
7172
static void test() {
7273
// Test 1
73-
const int16_t n1 = 8; // size of rod
74-
std::array<int32_t, n1> price1 = {1,2,4,6,8,45,21,9}; // price array
74+
const int16_t n1 = 8; // size of rod
75+
std::array<int32_t, n1> price1 = {1, 2, 4, 6, 8, 45, 21, 9}; // price array
7576
const int64_t max_profit1 =
7677
dynamic_programming::cut_rod::maxProfitByCuttingRod(price1, n1);
7778
const int64_t expected_max_profit1 = 47;
@@ -86,15 +87,15 @@ static void test() {
8687
31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
8788
41, 42, 43, 44, 45, 46, 47, 48, 49, 50};
8889

89-
const int64_t max_profit2=
90+
const int64_t max_profit2 =
9091
dynamic_programming::cut_rod::maxProfitByCuttingRod(price2, n2);
9192
const int32_t expected_max_profit2 = 90;
9293
assert(max_profit2 == expected_max_profit2);
9394
std::cout << "Maximum profit with " << n2 << " inch road is " << max_profit2
9495
<< std::endl;
95-
// Test 3
96-
const int16_t n3 = 5; // size of rod
97-
std::array<int32_t, n3> price3 = {2,9,17,23,45}; // price array
96+
// Test 3
97+
const int16_t n3 = 5; // size of rod
98+
std::array<int32_t, n3> price3 = {2, 9, 17, 23, 45}; // price array
9899
const int64_t max_profit3 =
99100
dynamic_programming::cut_rod::maxProfitByCuttingRod(price3, n3);
100101
const int64_t expected_max_profit3 = 45;

dynamic_programming/house_robber.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
#include <cassert> /// for assert
1313
#include <climits> /// for std::max
14+
#include <cstdint> /// for std::uint32_t
1415
#include <iostream> /// for io operations
1516
#include <vector> /// for std::vector
16-
1717
/**
1818
* @namespace dynamic_programming
1919
* @brief Dynamic Programming algorithms

dynamic_programming/longest_increasing_subsequence.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include <cassert> /// for assert
2323
#include <climits> /// for std::max
24+
#include <cstdint> /// for std::uint64_t
2425
#include <iostream> /// for IO operations
2526
#include <vector> /// for std::vector
2627

Lines changed: 76 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
/**
22
* @file
3-
* @brief Implementation of [Minimum Edit Distance](https://en.wikipedia.org/wiki/Edit_distance) using Dynamic Programing
3+
* @brief Implementation of [Minimum Edit
4+
* Distance](https://en.wikipedia.org/wiki/Edit_distance) using Dynamic
5+
* Programing
46
*
57
* @details
68
*
@@ -32,9 +34,11 @@
3234
* @author [Nirjas Jakilim](github.com/nirzak)
3335
*/
3436

35-
#include <cassert> /// for assert
36-
#include <iostream> /// for IO operations
37+
#include <cassert> /// for assert
38+
#include <cstdint> /// for std::uint64_t
39+
#include <iostream> /// for IO operations
3740
#include <vector> /// for std::vector
41+
3842
/**
3943
* @namespace dynamic_programming
4044
* @brief Dynamic Programming algorithms
@@ -44,7 +48,8 @@ namespace dynamic_programming {
4448

4549
/**
4650
* @namespace Minimum Edit Distance
47-
* @brief Implementation of [Minimum Edit Distance](https://en.wikipedia.org/wiki/Edit_distance) algorithm
51+
* @brief Implementation of [Minimum Edit
52+
* Distance](https://en.wikipedia.org/wiki/Edit_distance) algorithm
4853
*/
4954

5055
namespace minimum_edit_distance {
@@ -61,15 +66,14 @@ namespace minimum_edit_distance {
6166
* @returns z if `z` is the minimum value
6267
*/
6368
uint64_t min(uint64_t x, uint64_t y, uint64_t z) {
64-
if (x <= y && x <= z) {
65-
return x; /// returns x, if x is the minimum value
66-
}
67-
if (y <= x && y <= z) {
68-
return y; /// returns y, if y is the minimum value
69-
}
70-
else {
71-
return z; /// returns z if z is the minimum value
72-
}
69+
if (x <= y && x <= z) {
70+
return x; /// returns x, if x is the minimum value
71+
}
72+
if (y <= x && y <= z) {
73+
return y; /// returns y, if y is the minimum value
74+
} else {
75+
return z; /// returns z if z is the minimum value
76+
}
7377
}
7478

7579
/**
@@ -85,42 +89,48 @@ uint64_t min(uint64_t x, uint64_t y, uint64_t z) {
8589
* @returns dp[m][n] the minimum cost of operations
8690
* needed to convert str1 to str2
8791
*/
88-
uint64_t editDistDP(std::string str1, std::string str2, uint64_t m, uint64_t n) {
89-
/// Create a table to store results of subproblems
90-
std::vector<std::vector<uint64_t>>dp(m+1, std::vector<uint64_t>(n+1)); /// creasting 2D vector dp to store the results of subproblems
92+
uint64_t editDistDP(std::string str1, std::string str2, uint64_t m,
93+
uint64_t n) {
94+
/// Create a table to store results of subproblems
95+
std::vector<std::vector<uint64_t>> dp(
96+
m + 1,
97+
std::vector<uint64_t>(
98+
n +
99+
1)); /// creasting 2D vector dp to store the results of subproblems
91100

92-
/// Fill d[][] in bottom up manner
93-
for (uint64_t i = 0; i <= m; i++) {
94-
for (uint64_t j = 0; j <= n; j++) {
95-
/// If first string is empty, only option is to
96-
/// insert all characters of second string
97-
if (i == 0) {
98-
dp[i][j] = j; /// Minimum operations = j
99-
}
101+
/// Fill d[][] in bottom up manner
102+
for (uint64_t i = 0; i <= m; i++) {
103+
for (uint64_t j = 0; j <= n; j++) {
104+
/// If first string is empty, only option is to
105+
/// insert all characters of second string
106+
if (i == 0) {
107+
dp[i][j] = j; /// Minimum operations = j
108+
}
100109

101-
/// If second string is empty, only option is to
102-
/// remove all characters of second string
103-
else if (j == 0) {
104-
dp[i][j] = i; /// Minimum operations = i
105-
}
110+
/// If second string is empty, only option is to
111+
/// remove all characters of second string
112+
else if (j == 0) {
113+
dp[i][j] = i; /// Minimum operations = i
114+
}
106115

107-
/// If last characters are same, ignore last char
108-
/// and recur for remaining string
109-
else if (str1[i - 1] == str2[j - 1]) {
110-
dp[i][j] = dp[i - 1][j - 1];
111-
}
116+
/// If last characters are same, ignore last char
117+
/// and recur for remaining string
118+
else if (str1[i - 1] == str2[j - 1]) {
119+
dp[i][j] = dp[i - 1][j - 1];
120+
}
112121

113-
/// If the last character is different, consider all
114-
/// possibilities and find the minimum
115-
else {
116-
dp[i][j] = 1 + min(dp[i][j - 1], // Insert
117-
dp[i - 1][j], // Remove
118-
dp[i - 1][j - 1]); // Replace
119-
}
122+
/// If the last character is different, consider all
123+
/// possibilities and find the minimum
124+
else {
125+
dp[i][j] = 1 + min(dp[i][j - 1], // Insert
126+
dp[i - 1][j], // Remove
127+
dp[i - 1][j - 1]); // Replace
128+
}
129+
}
120130
}
121-
}
122131

123-
return dp[m][n]; /// returning the minimum cost of operations needed to convert str1 to str2
132+
return dp[m][n]; /// returning the minimum cost of operations needed to
133+
/// convert str1 to str2
124134
}
125135
} // namespace minimum_edit_distance
126136
} // namespace dynamic_programming
@@ -130,25 +140,28 @@ uint64_t editDistDP(std::string str1, std::string str2, uint64_t m, uint64_t n)
130140
* @returns void
131141
*/
132142
static void test() {
133-
// 1st test
134-
std::string str1 = "INTENTION"; // Sample input of 1st string
135-
std::string str2 = "EXECUTION"; // Sample input of 2nd string
136-
uint64_t expected_output1 = 5; // Expected minimum cost
137-
uint64_t output1 = dynamic_programming::minimum_edit_distance::editDistDP(
138-
str1, str2, str1.length(), str2.length()); // calling the editDistDP function and storing the result on output1
139-
assert(output1 == expected_output1); // comparing the output with the expected output
140-
std::cout << "Minimum Number of Operations Required: " << output1
141-
<< std::endl;
143+
// 1st test
144+
std::string str1 = "INTENTION"; // Sample input of 1st string
145+
std::string str2 = "EXECUTION"; // Sample input of 2nd string
146+
uint64_t expected_output1 = 5; // Expected minimum cost
147+
uint64_t output1 = dynamic_programming::minimum_edit_distance::editDistDP(
148+
str1, str2, str1.length(),
149+
str2.length()); // calling the editDistDP function and storing the
150+
// result on output1
151+
assert(output1 ==
152+
expected_output1); // comparing the output with the expected output
153+
std::cout << "Minimum Number of Operations Required: " << output1
154+
<< std::endl;
142155

143-
// 2nd test
144-
std::string str3 = "SATURDAY";
145-
std::string str4 = "SUNDAY";
146-
uint64_t expected_output2 = 3;
147-
uint64_t output2 = dynamic_programming::minimum_edit_distance::editDistDP(
148-
str3, str4, str3.length(), str4.length());
149-
assert(output2 == expected_output2);
150-
std::cout << "Minimum Number of Operations Required: " << output2
151-
<< std::endl;
156+
// 2nd test
157+
std::string str3 = "SATURDAY";
158+
std::string str4 = "SUNDAY";
159+
uint64_t expected_output2 = 3;
160+
uint64_t output2 = dynamic_programming::minimum_edit_distance::editDistDP(
161+
str3, str4, str3.length(), str4.length());
162+
assert(output2 == expected_output2);
163+
std::cout << "Minimum Number of Operations Required: " << output2
164+
<< std::endl;
152165
}
153166

154167
/**
@@ -158,6 +171,6 @@ static void test() {
158171
* @returns 0 on exit
159172
*/
160173
int main(int argc, char *argv[]) {
161-
test(); // run self-test implementations
162-
return 0;
174+
test(); // run self-test implementations
175+
return 0;
163176
}

dynamic_programming/partition_problem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@
2828
*
2929
*******************************************************************************/
3030
#include <cassert> /// for assert
31+
#include <cstdint> /// for std::uint64_t
3132
#include <iostream> /// for IO Operations
3233
#include <numeric> /// for std::accumulate
3334
#include <vector> /// for std::vector
34-
3535
/******************************************************************************
3636
* @namespace dp
3737
* @brief Dynamic programming algorithms

operations_on_datastructures/trie_multiple_search.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/**
22
* @file
3-
* @brief [Trie datastructure](https://iq.opengenus.org/autocomplete-using-trie-data-structure/)
3+
* @brief [Trie
4+
* datastructure](https://iq.opengenus.org/autocomplete-using-trie-data-structure/)
45
* with search variants
56
* @details
67
* This provides multiple variants of search functions
@@ -12,6 +13,7 @@
1213
#include <algorithm> /// for std::count
1314
#include <cassert> /// for assert
1415
#include <cctype> /// for tolower
16+
#include <cstdint> /// for std::uint32_t
1517
#include <cstring> /// for string operations
1618
#include <iostream> /// for IO Operations
1719
#include <queue> /// for std::priority_queue
@@ -23,7 +25,8 @@
2325
namespace operations_on_datastructures {
2426
/**
2527
* @namespace trie_operations
26-
* @brief Functions for [Trie datastructure](https://iq.opengenus.org/autocomplete-using-trie-data-structure/)
28+
* @brief Functions for [Trie
29+
* datastructure](https://iq.opengenus.org/autocomplete-using-trie-data-structure/)
2730
* implementation
2831
*/
2932
namespace trie_operations {

range_queries/segtree.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include <cassert> /// for assert
2323
#include <cmath> /// for log2
24+
#include <cstdint> /// for std::uint64_t
2425
#include <iostream> /// for IO operations
2526
#include <vector> /// for std::vector
2627

0 commit comments

Comments
 (0)