Skip to content

Commit b0ad83e

Browse files
committed
Add Max Recursivo
1 parent a5a669e commit b0ad83e

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/cpp/MaximoRecursivo.cpp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,25 @@
22
#include <vector>
33

44

5-
int max_recursivo(std::vector<int> nums, int n, int max) {
5+
int max_recursivo(std::vector<int> nums, int n) {
66

77
if(n == 1)
88
return nums[0];
9-
10-
11-
12-
13-
9+
else{
10+
int aux = max_recursivo(nums, n-1);
11+
12+
if(aux > nums[n-1])
13+
return aux;
14+
15+
return nums[n-1];
16+
}
1417
}
1518

1619
int main() {
1720

18-
std::vector<int> nums{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
21+
std::vector<int> nums{1, 2, 3, 4, 32, 6, 7, 8, 9, 10};
1922

20-
// std::cout << max_recursivo(nums, nums.size()) << std::endl;
23+
std::cout << max_recursivo(nums, nums.size()) << std::endl;
2124

2225
return 0;
2326
}

0 commit comments

Comments
 (0)