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 & vec1)

{

int maxSum = 0;

int thisSum = 0;

int k = 0;

vector subseq;

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 vec1;

vector subseq;

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!