一、代碼說明:
由于數據分析需要,按照規定的上、下限值,剔除數組中超出上下限的數據。
代碼中使用了 C++ 標準庫里?std::list 的函數:remove_if()。非常簡捷明了。
二、代碼實現:
/剔除數組中的無效數據
extern "C" __declspec(dllexport) int RemoveInvalidData(double* input, long size_input, double* output, long &size_output) {
?
? ? vector<double> vecTmp(input, input + size_input);
? ? list<double> dataList;
? ? dataList.assign(vecTmp.begin(), vecTmp.end());
?
? ? //剔除超出上下界的數據
? ? dataList.remove_if([](double i) { return (i > 28.50 || i < 24.0); });
?
? ? ? ? ......
?
}