I use structs for just clumping some values together when they're not really a complex object. That way, I reserve classes for things which are actually objects and not e.g. just some intermediate values that got passed back from a function or a bunch of settings. Also, say you have a world location in a game. You might have a lot of objects which deal with the concept of a "location" so you bundle them into a class. but is "my location" really an object? Usually I just make that a struct for that reason.
Anyway here's the algorithm you asked for written in C++ dialect. You'll notice that by creating an appropriate data structure, I was able to keep it nearly identical on a line-by-line basis:
struct Data // generic "Data" name because I don't actually know what it's for!
{
int low, high, sum;
Data(int _low, int _high, int _sum) : low(_low), high(_high), sum(_sum) {} // constructor so we can create the structs inline
}
Data FMS(int A[], int low, int high)
{
if (high == low)
return Data(low, high, A[low]);
else
{
int mid = (low + high) / 2;
Data left = FMS(A, low, mid);
Data right = FMS(A, mid + 1, high);
Data cross = FMCS(A, low, mid, high);
if (left.sum >= right.sum && left.sum >= cross.sum)
return Data(left.low, left.high, left.sum);
else if (right.sum >= left.sum && right.sum >= cross.sum)
return Data(right.low, right.high, right.sum);
else return Data(cross.low, cross.high, cross.sum);
}
}