I am new to C++, and I am trying to write a function to solve this challenge. The code I have looks like this:
#include <iostream>
#include <deque>
#include <algorithm>
using namespace std;
void printKMax(int arr[], int n, int k){
deque<int> subarray;
int i = arr.size();
int maxValues[n];
while(i >= 0) {
while (subarray.size() < n) {
subarray.push_back(arr[i]);
arr.pop();
--i;
}
maxValues.push(max_element(begin(subarray), end(subarray)));
subarray.pop_front();
}
for (array<int>::iterator it=maxValues.begin(); it!=maxValues.end();
it++) {
cout << maxValues[*it] << " ";
}
}
int main(){
int t;
cin >> t;
while(t>0) {
int n,k;
cin >> n >> k;
int i;
int arr[n];
for(i=0;i<n;i++)
cin >> arr[i];
printKMax(arr, n, k);
t--;
}
return 0;
}
This code is throwing, among other things, an error saying:
"request for member ‘size’ in ‘arr’, which is of non-class type ‘int*’ int i = arr.size();"
Can someone please help me understand what this means? Am I trying to reference something from outside of the class, so that I need to use a pointer? Is it a problem with the way the array is declared?
Thanks in advance!