Given an array X, the span S[i] of X[i] is the maximum number of consecutive elements X[j] immediately preceding X[i] and such that X[j] <= X[i]
Develop a C++ function that has an array of double numbers and the size of the array as its parameters, and then fill an integer array of the same size the span of each element in the first array.
The prototype of the function is shown below:
void calculateSpan(double X[], int size, int S[]);
First develop the function using a quadratic algorithm. (This should be easy).
Then develop a linear algorithm to solve the problem using a Stack. Try to analyze why this algorithm is a linear one.
Practice submit your solution electronically using the following steps: