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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started