Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Spatial Databases A Tour

Authors: Shashi Shekhar, Sanjay Chawla

1st Edition

0130174807, 978-0130174802

More Books

Students also viewed these Databases questions

Question

=+b. Create a tagline.

Answered: 1 week ago

Question

1. Identify outcomes (e.g., quality, accidents).

Answered: 1 week ago