struct STRU_PARENT_ELE { int m_count; QWebElement m_ele; STRU_PARENT_ELE() { clear(); } void clear() { m_count = 0; } };
void add_parent_ele(vector<STRU_PARENT_ELE>& vecElesParent, QWebElement ele) { size_t i = 0; for (; i < vecElesParent.size(); ++i) { if (vecElesParent[i].m_ele == ele) { ++vecElesParent[i].m_count; break; } } if (i >= vecElesParent.size()) //没有找到 { STRU_PARENT_ELE stru_parent_ele; stru_parent_ele.m_count = 1; stru_parent_ele.m_ele = ele; vecElesParent.push_back(stru_parent_ele); } }
int find_most_times_ele(const vector<STRU_PARENT_ELE>& vecElesParent) { int max_times_ele_index = 0; int temp_max_count = 0; for (size_t i = 0; i < vecElesParent.size(); ++i) { if (vecElesParent[i].m_count > temp_max_count) { temp_max_count = vecElesParent[i].m_count; max_times_ele_index = i; } } return max_times_ele_index; }
获取vector中出现次数最多的元素
最新推荐文章于 2022-04-28 16:26:41 发布