-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy path4.1.cpp
29 lines (22 loc) · 1 KB
/
4.1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include "4.1.h"
#include "../print.h"
using namespace CLRS::CH4;
int main() {
print(string("Chapter 4.1 The maximum-subarray problem"));
cout << "Initialize an array A as Figure 4.3\n";
vector<int> A = {13, -3, -25, 20, -3, -16, -23, 18,
20, -7, 12, -5, -22, 15, -4, 7};
print(A);
Ans ans = findMaximumSubarray(A, 0, 15);
cout << "\nPerform FIND-MAXIMUM-SUBARRAY(A, 0, 15)\n"
<< "The (low, high, sum) of the maximum subarray of A are (" << ans.low
<< ", " << ans.high << ", " << ans.sum << ")\n";
ans = bruteForceFindMaximumSubarray(A);
cout << "\nPerform FIND-MAXIMUM-SUBARRAY-BRUTE-FORCE(A)\n"
<< "The (low, high, sum) of the maximum subarray of A are (" << ans.low
<< ", " << ans.high << ", " << ans.sum << ")\n";
ans = iterativeFindMaximumSubarray(A);
cout << "\nPerform FIND-MAXIMUM-SUBARRAY-LINEAR(A)\n"
<< "The (low, high, sum) of the maximum subarray of A are (" << ans.low
<< ", " << ans.high << ", " << ans.sum << ")\n";
}