使用向量模板类 vector 实现以上功能的示例:
#include <iostream>
#include <vector>
using namespace std;
struct unit {
int maxValue;
int maxDeep;
};
bool myfuncUnit(const unit& i, const unit& j) {
return i.maxValue < j.maxValue;
}
vector<unit> pairVec;
unit tmp;
tmp.maxValue = val;
tmp.maxDeep = maxLevel;
pairVec.push_back(tmp);
sort(pairVec.begin(), pairVec.end(), myfuncUnit);
vector<unit>::iterator iter;
for (iter = pairVec.begin(); iter != pairVec.end();)
iter = pairVec.erase(iter);