Question: #include #include Vector.h #include using namespace std; int max_subseq_sum_alg4 ( const vector & vec1) { int maxSum = 0; int thisSum = 0; int k
#include
#include "Vector.h"
#include
using namespace std;
int max_subseq_sum_alg4 ( const vector
{
int maxSum = 0;
int thisSum = 0;
int k = 0;
vector
for (int i = 0; i < vec1.size() ; i++)
{
thisSum += vec1[i];
subseq[k] = vec1[i];
if (thisSum > maxSum)
maxSum = thisSum;
else if (thisSum < 0)
thisSum = 0;
subseq.push_back(i);
}
return maxSum;
return subseq.at(k);
}
int main()
{
vector
vector
int next;
for (int i=1; i<=10; i++)
{
cout << "interger: ";
cin >> next;
cout << endl;
vec1.push_back(next);
}
cout << endl;
cout << max_subseq_sum_alg4(vec1);
return 0;
}
I want my code to print out the subsequence of the max sum not just the max sum of a sequence.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
