diff --git a/d5/d7f/trapped__rainwater_8cpp__incl.map b/d5/d7f/trapped__rainwater_8cpp__incl.map new file mode 100644 index 000000000..df1c60e18 --- /dev/null +++ b/d5/d7f/trapped__rainwater_8cpp__incl.map @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/d5/d7f/trapped__rainwater_8cpp__incl.md5 b/d5/d7f/trapped__rainwater_8cpp__incl.md5 new file mode 100644 index 000000000..4981c3808 --- /dev/null +++ b/d5/d7f/trapped__rainwater_8cpp__incl.md5 @@ -0,0 +1 @@ +ba47674fb5ef86b11c883aeb698f3fc9 \ No newline at end of file diff --git a/d5/d7f/trapped__rainwater_8cpp__incl.svg b/d5/d7f/trapped__rainwater_8cpp__incl.svg new file mode 100644 index 000000000..6cfa20711 --- /dev/null +++ b/d5/d7f/trapped__rainwater_8cpp__incl.svg @@ -0,0 +1,138 @@ + + + + + + + + + + + + +dynamic_programming/trapped_rainwater.cpp + + +Node1 + + +dynamic_programming +/trapped_rainwater.cpp + + + + + +Node2 + + +algorithm + + + + + +Node1->Node2 + + + + + + + + +Node3 + + +cassert + + + + + +Node1->Node3 + + + + + + + + +Node4 + + +cstddef + + + + + +Node1->Node4 + + + + + + + + +Node5 + + +cstdint + + + + + +Node1->Node5 + + + + + + + + +Node6 + + +vector + + + + + +Node1->Node6 + + + + + + + + + + + + + diff --git a/d5/d7f/trapped__rainwater_8cpp__incl_org.svg b/d5/d7f/trapped__rainwater_8cpp__incl_org.svg new file mode 100644 index 000000000..d93aed2b7 --- /dev/null +++ b/d5/d7f/trapped__rainwater_8cpp__incl_org.svg @@ -0,0 +1,112 @@ + + + + + + +dynamic_programming/trapped_rainwater.cpp + + +Node1 + + +dynamic_programming +/trapped_rainwater.cpp + + + + + +Node2 + + +algorithm + + + + + +Node1->Node2 + + + + + + + + +Node3 + + +cassert + + + + + +Node1->Node3 + + + + + + + + +Node4 + + +cstddef + + + + + +Node1->Node4 + + + + + + + + +Node5 + + +cstdint + + + + + +Node1->Node5 + + + + + + + + +Node6 + + +vector + + + + + +Node1->Node6 + + + + + + + + diff --git a/d9/d80/trapped__rainwater_8cpp.html b/d9/d80/trapped__rainwater_8cpp.html new file mode 100644 index 000000000..9d6eca16f --- /dev/null +++ b/d9/d80/trapped__rainwater_8cpp.html @@ -0,0 +1,258 @@ + + + + + + + +Algorithms_in_C++: dynamic_programming/trapped_rainwater.cpp File Reference + + + + + + + + + + + + + + + + + +
+
+ + + + + + +
+
Algorithms_in_C++ 1.0.0 +
+
Set of algorithms implemented in C++.
+
+
+ + + + + + + + +
+
+ +
+
+
+ +
+ +
+
+ + +
+
+
+
+
+
Loading...
+
Searching...
+
No Matches
+
+
+
+
+ +
+ +
trapped_rainwater.cpp File Reference
+
+
+ +

Implementation of the Trapped Rainwater Problem +More...

+
#include <algorithm>
+#include <cassert>
+#include <cstddef>
+#include <cstdint>
+#include <vector>
+
+Include dependency graph for trapped_rainwater.cpp:
+
+
+
+
+ + + + +

+Namespaces

namespace  dynamic_programming
 Dynamic Programming algorithms.
 
+ + + + + + + + + + +

+Functions

uint32_t dynamic_programming::trappedRainwater (const std::vector< uint32_t > &heights)
 Function to calculate the trapped rainwater.
 
static void test ()
 Self-test implementations.
 
int main ()
 Main function.
 
+

Detailed Description

+

Implementation of the Trapped Rainwater Problem

+

This implementation calculates the amount of rainwater that can be trapped between walls represented by an array of heights.

Author
SOZEL
+

Function Documentation

+ +

◆ main()

+ +
+
+ + + + + + + +
int main (void )
+
+ +

Main function.

+
Returns
0 on exit
+
101 {
+
102 test(); // run self-test implementations
+
103 return 0;
+
104}
+
static void test()
Self-test implementations.
Definition trapped_rainwater.cpp:62
+
+Here is the call graph for this function:
+
+
+
+ +
+
+ +

◆ test()

+ +
+
+ + + + + +
+ + + + + + + +
static void test ()
+
+static
+
+ +

Self-test implementations.

+
Returns
void
+
62 {
+
63 std::vector<uint32_t> test_basic = {0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1};
+
64 assert(dynamic_programming::trappedRainwater(test_basic) == 6);
+
65
+
66 std::vector<uint32_t> test_peak_under_water = {3, 0, 2, 0, 4};
+
67 assert(dynamic_programming::trappedRainwater(test_peak_under_water) == 7);
+
68
+
69 std::vector<uint32_t> test_bucket = {5, 1, 5};
+
70 assert(dynamic_programming::trappedRainwater(test_bucket) == 4);
+
71
+
72 std::vector<uint32_t> test_skewed_bucket = {4, 1, 5};
+
73 assert(dynamic_programming::trappedRainwater(test_skewed_bucket) == 3);
+
74
+
75 std::vector<uint32_t> test_empty = {};
+
76 assert(dynamic_programming::trappedRainwater(test_empty) == 0);
+
77
+
78 std::vector<uint32_t> test_flat = {0, 0, 0, 0, 0};
+
79 assert(dynamic_programming::trappedRainwater(test_flat) == 0);
+
80
+
81 std::vector<uint32_t> test_no_trapped_water = {1, 1, 2, 4, 0, 0, 0};
+
82 assert(dynamic_programming::trappedRainwater(test_no_trapped_water) == 0);
+
83
+
84 std::vector<uint32_t> test_single_elevation = {5};
+
85 assert(dynamic_programming::trappedRainwater(test_single_elevation) == 0);
+
86
+
87 std::vector<uint32_t> test_two_point_elevation = {5, 1};
+
88 assert(dynamic_programming::trappedRainwater(test_two_point_elevation) ==
+
89 0);
+
90
+
91 std::vector<uint32_t> test_large_elevation_map_difference = {5, 1, 6, 1,
+
92 7, 1, 8};
+ +
94 test_large_elevation_map_difference) == 15);
+
95}
+
uint32_t trappedRainwater(const std::vector< uint32_t > &heights)
Function to calculate the trapped rainwater.
Definition trapped_rainwater.cpp:27
+ +
+Here is the call graph for this function:
+
+
+
+ +
+
+
+
+ + + + diff --git a/d9/d80/trapped__rainwater_8cpp.js b/d9/d80/trapped__rainwater_8cpp.js new file mode 100644 index 000000000..280ba5344 --- /dev/null +++ b/d9/d80/trapped__rainwater_8cpp.js @@ -0,0 +1,6 @@ +var trapped__rainwater_8cpp = +[ + [ "main", "d9/d80/trapped__rainwater_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4", null ], + [ "test", "d9/d80/trapped__rainwater_8cpp.html#aa8dca7b867074164d5f45b0f3851269d", null ], + [ "trappedRainwater", "d9/d80/trapped__rainwater_8cpp.html#a066e0e739e7c276eee6e61d5b4d37ce8", null ] +]; \ No newline at end of file diff --git a/d9/d80/trapped__rainwater_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.map b/d9/d80/trapped__rainwater_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.map new file mode 100644 index 000000000..f8ab413f7 --- /dev/null +++ b/d9/d80/trapped__rainwater_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.map @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/d9/d80/trapped__rainwater_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.md5 b/d9/d80/trapped__rainwater_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.md5 new file mode 100644 index 000000000..9e81044d7 --- /dev/null +++ b/d9/d80/trapped__rainwater_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.md5 @@ -0,0 +1 @@ +24ed3c31a50a8e646f51ce7bd657d22a \ No newline at end of file diff --git a/d9/d80/trapped__rainwater_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.svg b/d9/d80/trapped__rainwater_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.svg new file mode 100644 index 000000000..2e96af854 --- /dev/null +++ b/d9/d80/trapped__rainwater_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph.svg @@ -0,0 +1,120 @@ + + + + + + + + + + + + +test + + +Node1 + + +test + + + + + +Node2 + + +dynamic_programming +::trappedRainwater + + + + + +Node1->Node2 + + + + + + + + +Node3 + + +std::max + + + + + +Node2->Node3 + + + + + + + + +Node4 + + +std::min + + + + + +Node2->Node4 + + + + + + + + +Node5 + + +std::vector::size + + + + + +Node2->Node5 + + + + + + + + + + + + + diff --git a/d9/d80/trapped__rainwater_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph_org.svg b/d9/d80/trapped__rainwater_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph_org.svg new file mode 100644 index 000000000..49d6799d6 --- /dev/null +++ b/d9/d80/trapped__rainwater_8cpp_aa8dca7b867074164d5f45b0f3851269d_cgraph_org.svg @@ -0,0 +1,94 @@ + + + + + + +test + + +Node1 + + +test + + + + + +Node2 + + +dynamic_programming +::trappedRainwater + + + + + +Node1->Node2 + + + + + + + + +Node3 + + +std::max + + + + + +Node2->Node3 + + + + + + + + +Node4 + + +std::min + + + + + +Node2->Node4 + + + + + + + + +Node5 + + +std::vector::size + + + + + +Node2->Node5 + + + + + + + + diff --git a/d9/d80/trapped__rainwater_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.map b/d9/d80/trapped__rainwater_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.map new file mode 100644 index 000000000..22d23d3bb --- /dev/null +++ b/d9/d80/trapped__rainwater_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.map @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/d9/d80/trapped__rainwater_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.md5 b/d9/d80/trapped__rainwater_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.md5 new file mode 100644 index 000000000..f5adb3637 --- /dev/null +++ b/d9/d80/trapped__rainwater_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.md5 @@ -0,0 +1 @@ +9d9b9a28bb3fd483ee9089311f8f072a \ No newline at end of file diff --git a/d9/d80/trapped__rainwater_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg b/d9/d80/trapped__rainwater_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg new file mode 100644 index 000000000..294a81037 --- /dev/null +++ b/d9/d80/trapped__rainwater_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg @@ -0,0 +1,138 @@ + + + + + + + + + + + + +main + + +Node1 + + +main + + + + + +Node2 + + +test + + + + + +Node1->Node2 + + + + + + + + +Node3 + + +dynamic_programming +::trappedRainwater + + + + + +Node2->Node3 + + + + + + + + +Node4 + + +std::max + + + + + +Node3->Node4 + + + + + + + + +Node5 + + +std::min + + + + + +Node3->Node5 + + + + + + + + +Node6 + + +std::vector::size + + + + + +Node3->Node6 + + + + + + + + + + + + + diff --git a/d9/d80/trapped__rainwater_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph_org.svg b/d9/d80/trapped__rainwater_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph_org.svg new file mode 100644 index 000000000..b290ca3fe --- /dev/null +++ b/d9/d80/trapped__rainwater_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph_org.svg @@ -0,0 +1,112 @@ + + + + + + +main + + +Node1 + + +main + + + + + +Node2 + + +test + + + + + +Node1->Node2 + + + + + + + + +Node3 + + +dynamic_programming +::trappedRainwater + + + + + +Node2->Node3 + + + + + + + + +Node4 + + +std::max + + + + + +Node3->Node4 + + + + + + + + +Node5 + + +std::min + + + + + +Node3->Node5 + + + + + + + + +Node6 + + +std::vector::size + + + + + +Node3->Node6 + + + + + + + + diff --git a/dd/d24/namespacedynamic__programming.html b/dd/d24/namespacedynamic__programming.html index 743f06be6..6e006a473 100644 --- a/dd/d24/namespacedynamic__programming.html +++ b/dd/d24/namespacedynamic__programming.html @@ -128,6 +128,9 @@ Functions int maxCircularSum (std::vector< int > &arr)  returns the maximum contiguous circular sum of an array
  +uint32_t trappedRainwater (const std::vector< uint32_t > &heights) + Function to calculate the trapped rainwater.
+ 

Detailed Description

Dynamic Programming algorithms.

@@ -148,7 +151,8 @@ Functions

Dynamic Programming algorithms

for assert for IO operations for std::vector

for std::assert for IO operations for unordered map

-

Dynamic Programming algorithms

+

Dynamic Programming algorithms

+

For std::min and std::max For assert For std::size_t For integral typedefs For std::vector

Function Documentation

◆ is_armstrong()

@@ -411,6 +415,66 @@ Here is the call graph for this function:
+ + + +

◆ trappedRainwater()

+ +
+
+ + + + + + + +
uint32_t dynamic_programming::trappedRainwater (const std::vector< uint32_t > & heights)
+
+ +

Function to calculate the trapped rainwater.

+
Parameters
+ + +
heightsArray representing the heights of walls
+
+
+
Returns
The amount of trapped rainwater
+
27 {
+
28 std::size_t n = heights.size();
+
29 if (n <= 2)
+
30 return 0; // No water can be trapped with less than 3 walls
+
31
+
32 std::vector<uint32_t> leftMax(n), rightMax(n);
+
33
+
34 // Calculate the maximum height of wall to the left of each wall
+
35 leftMax[0] = heights[0];
+
36 for (std::size_t i = 1; i < n; ++i) {
+
37 leftMax[i] = std::max(leftMax[i - 1], heights[i]);
+
38 }
+
39
+
40 // Calculate the maximum height of wall to the right of each wall
+
41 rightMax[n - 1] = heights[n - 1];
+
42 for (std::size_t i = n - 2; i < n; --i) {
+
43 rightMax[i] = std::max(rightMax[i + 1], heights[i]);
+
44 }
+
45
+
46 // Calculate the trapped rainwater between walls
+
47 uint32_t trappedWater = 0;
+
48 for (std::size_t i = 0; i < n; ++i) {
+
49 trappedWater +=
+
50 std::max(0u, std::min(leftMax[i], rightMax[i]) - heights[i]);
+
51 }
+
52
+
53 return trappedWater;
+
54}
+ +
+Here is the call graph for this function:
+
+
+
+
diff --git a/dd/d24/namespacedynamic__programming_a066e0e739e7c276eee6e61d5b4d37ce8_cgraph.map b/dd/d24/namespacedynamic__programming_a066e0e739e7c276eee6e61d5b4d37ce8_cgraph.map new file mode 100644 index 000000000..72f878475 --- /dev/null +++ b/dd/d24/namespacedynamic__programming_a066e0e739e7c276eee6e61d5b4d37ce8_cgraph.map @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/dd/d24/namespacedynamic__programming_a066e0e739e7c276eee6e61d5b4d37ce8_cgraph.md5 b/dd/d24/namespacedynamic__programming_a066e0e739e7c276eee6e61d5b4d37ce8_cgraph.md5 new file mode 100644 index 000000000..15d9ca50b --- /dev/null +++ b/dd/d24/namespacedynamic__programming_a066e0e739e7c276eee6e61d5b4d37ce8_cgraph.md5 @@ -0,0 +1 @@ +d46ed760551b143c23aab1cdfba3dfb6 \ No newline at end of file diff --git a/dd/d24/namespacedynamic__programming_a066e0e739e7c276eee6e61d5b4d37ce8_cgraph.svg b/dd/d24/namespacedynamic__programming_a066e0e739e7c276eee6e61d5b4d37ce8_cgraph.svg new file mode 100644 index 000000000..b2a6fd626 --- /dev/null +++ b/dd/d24/namespacedynamic__programming_a066e0e739e7c276eee6e61d5b4d37ce8_cgraph.svg @@ -0,0 +1,102 @@ + + + + + + + + + + + + +dynamic_programming::trappedRainwater + + +Node1 + + +dynamic_programming +::trappedRainwater + + + + + +Node2 + + +std::max + + + + + +Node1->Node2 + + + + + + + + +Node3 + + +std::min + + + + + +Node1->Node3 + + + + + + + + +Node4 + + +std::vector::size + + + + + +Node1->Node4 + + + + + + + + + + + + + diff --git a/dd/d24/namespacedynamic__programming_a066e0e739e7c276eee6e61d5b4d37ce8_cgraph_org.svg b/dd/d24/namespacedynamic__programming_a066e0e739e7c276eee6e61d5b4d37ce8_cgraph_org.svg new file mode 100644 index 000000000..4d3200039 --- /dev/null +++ b/dd/d24/namespacedynamic__programming_a066e0e739e7c276eee6e61d5b4d37ce8_cgraph_org.svg @@ -0,0 +1,76 @@ + + + + + + +dynamic_programming::trappedRainwater + + +Node1 + + +dynamic_programming +::trappedRainwater + + + + + +Node2 + + +std::max + + + + + +Node1->Node2 + + + + + + + + +Node3 + + +std::min + + + + + +Node1->Node3 + + + + + + + + +Node4 + + +std::vector::size + + + + + +Node1->Node4 + + + + + + + + diff --git a/dir_8a20dd5bfd5341a725342bf72b6b686f.html b/dir_8a20dd5bfd5341a725342bf72b6b686f.html index d17b635e7..a45ff82f2 100644 --- a/dir_8a20dd5bfd5341a725342bf72b6b686f.html +++ b/dir_8a20dd5bfd5341a725342bf72b6b686f.html @@ -155,6 +155,9 @@ Files  subset_sum.cpp  Implements [Sub-set sum problem] (https://en.wikipedia.org/wiki/Subset_sum_problem) algorithm, which tells whether a subset with target sum exists or not.
  + trapped_rainwater.cpp + Implementation of the Trapped Rainwater Problem
+   word_break.cpp  Word Break Problem
  diff --git a/dir_8a20dd5bfd5341a725342bf72b6b686f.js b/dir_8a20dd5bfd5341a725342bf72b6b686f.js index 728e6ca98..63b4c2cc8 100644 --- a/dir_8a20dd5bfd5341a725342bf72b6b686f.js +++ b/dir_8a20dd5bfd5341a725342bf72b6b686f.js @@ -15,5 +15,6 @@ var dir_8a20dd5bfd5341a725342bf72b6b686f = [ "palindrome_partitioning.cpp", "d5/d90/palindrome__partitioning_8cpp.html", "d5/d90/palindrome__partitioning_8cpp" ], [ "shortest_common_supersequence.cpp", "d7/d65/shortest__common__supersequence_8cpp.html", "d7/d65/shortest__common__supersequence_8cpp" ], [ "subset_sum.cpp", "d6/d80/dynamic__programming_2subset__sum_8cpp.html", "d6/d80/dynamic__programming_2subset__sum_8cpp" ], + [ "trapped_rainwater.cpp", "d9/d80/trapped__rainwater_8cpp.html", "d9/d80/trapped__rainwater_8cpp" ], [ "word_break.cpp", "d3/d84/word__break_8cpp.html", "d3/d84/word__break_8cpp" ] ]; \ No newline at end of file diff --git a/doxygen_crawl.html b/doxygen_crawl.html index 76f17fe10..6fb712fc7 100644 --- a/doxygen_crawl.html +++ b/doxygen_crawl.html @@ -97,6 +97,7 @@ + @@ -2720,6 +2721,10 @@ + + + + @@ -3416,6 +3421,7 @@ + diff --git a/files.html b/files.html index 43d80f88c..5190234fd 100644 --- a/files.html +++ b/files.html @@ -192,7 +192,8 @@ solve-a-rat-in-a-maze-c-java-pytho/" target="_blank">Rat in a Maze algorithm  palindrome_partitioning.cppImplements Palindrome Partitioning algorithm, giving you the minimum number of partitions you need to make  shortest_common_supersequence.cppSCS is a string Z which is the shortest supersequence of strings X and Y (may not be continuous in Z, but order is maintained)  subset_sum.cppImplements [Sub-set sum problem] (https://en.wikipedia.org/wiki/Subset_sum_problem) algorithm, which tells whether a subset with target sum exists or not - word_break.cppWord Break Problem + trapped_rainwater.cppImplementation of the Trapped Rainwater Problem + word_break.cppWord Break Problem  ► games  memory_game.cppA simple Memory Game with 3 different sizes and multiple letters  ► geometry diff --git a/globals_func_m.html b/globals_func_m.html index 713cf033d..4e485a4cb 100644 --- a/globals_func_m.html +++ b/globals_func_m.html @@ -107,7 +107,7 @@ $(function(){initNavTree('globals_func_m.html',''); initResizable(true); });
Here is a list of all documented functions with links to the documentation:

- m -