////////////////////////////////////
struct Rank
{
CString strUsername;
CString strTimestamp;
UINT uiRank;
};
typedef ::std::vector<Rank> MyRankArray;
bool RankCompDesc(const Rank & rFirst, const Rank & rSecond)
{
return rFirst.uiRank < rSecond.uiRank;
}
bool RankCompInc(const Rank & rFirst, const Rank & rSecond)
{
return rFirst.uiRank > rSecond.uiRank;
}
MyRankArray m_aRank;
....
sort(m_aRank.begin(), m_aRank.end(), bInc ? RankCompInc : RankCompDesc);
////////////////////////////////////
struct Exercise
{
CString strRule;
UINT uiElapsedTime;
UINT uiRightCounter;
};
class IsSameRule
{
public:
IsSameRule(const CString strKey):strRule(strKey){}
bool operator ()(const MyExerciseArray::value_type & value)
{
return value.strRule == strRule;
}
private:
CString strRule;
};
MyExerciseArray::iterator itr;
Exercise ex;
ex.strRule = ...;
ex.uiElapsedTime = ...;
ex.uiRightCounter = ...;
itr = find_if(m_aExercise.begin(), m_aExercise.end(), IsSameRule(ex.strRule));
if(itr == m_aExercise.end())
{
//not found
m_aExercise.push_back(ex);
}
else
{
itr->uiElapsedTime += ex.uiElapsedTime;
itr->uiRightCounter += ex.uiRightCounter;
}
////////////////////////////////////