I'm doing the max circular subarray sum problem in C++ on 'geeks for geeks' .org. I'm a noob and probably doing something simple wrong.
Errors:
prog.cpp:8:6: error: an anonymous struct cannot have function members
class{
^
prog.cpp:40:2: error: abstract declarator <anonymous class> used as declaration
};
^
prog.cpp: In function int main():
prog.cpp:63:6: error: Solution was not declared in this scope
Solution ob;
^
prog.cpp:65:14: error: ob was not declared in this scope
cout << ob.circularSubarraySum(arr, num) << endl;
Here's my code:
// } Driver Code Ends
class{
public:
// arr: input array
// num: size of array
//Function to find maximum circular subarray sum.
static int circularSubarraySum(int arr[], int num){
#include <cmath>
int n = ceil(num/2);
int maxCircSub[n];
int i = num - 1;
int j = 0;
while (i > floor(num/2)){
if (arr[i] > arr[j]){
maxCircSub[n] = arr[i];
}else{
maxCircSub[n] = arr[j];
}
i--;
j++;
}
int k = 0;
int sum = 0;
while (k < j){
sum += maxCircSub[k];
k++;
}
return sum;
}
};
// { Driver Code Starts.
Thank you for your help.