【C++】代码实现:运用 std::list 的 remove_if() 函数剔除数组中超出上下限的数据

一、代码说明:

由于数据分析需要,按照规定的上、下限值,剔除数组中超出上下限的数据。

代码中使用了 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); });

        ......

}

猜你喜欢

转载自blog.csdn.net/kingkee/article/details/94432044