I would like to add the peak position of a vector and the peak number but I can't find a way to add the elements and then return it, or write it on console.
#include <iostream>
#include <vector>
using namespace std;
struct PeakData {
vector<int> pos, peaks;
};
PeakData pick_peaks(vector<int> v) {
PeakData result;
for (int i = 1; i < v.size() - 1; i++) {
if ((v[i] > v[i - 1]) && (v[i] > v[i + 1])) {
result.peaks.push_back(v[i]);
result.pos.push_back(i);
}
}
return result;
}
Example: pickPeaks([3, 2, 3, 6, 4, 1, 2, 3, 2, 1, 2, 3]) should return {pos: [3, 7], peaks: [6, 3]}