1.list排序
struct NOTIFY_RECEIVE_HISTORY_GameInfo_PACKET
{
char Gmcode[4] ; //游戏编号
char round[16]; //期号
uint64 Time2 ; //开始时间
uint32 resbits; //该期输赢结果,玩法对应位1则赢。玩法值见附录
uint16 sum; //总和
char reslst[20]; //结果列表
NOTIFY_RECEIVE_HISTORY_GameInfo_PACKET()
{
memset(this,0,sizeof(NOTIFY_RECEIVE_HISTORY_GameInfo_PACKET));
}
};
class SortHistoryGameInfo_Cmp //最基本的排序函数
{
public:
bool operator()(NOTIFY_RECEIVE_HISTORY_GameInfo_PACKET& gameinfo1,NOTIFY_RECEIVE_HISTORY_GameInfo_PACKET& gameinfo2) const
{
if ( strlen(gameinfo1.round) == 0)
return FALSE;
if ( strcmp(gameinfo1.round , gameinfo2.round) > 0 )
return TRUE;
else
return FALSE;
}
};
SortHistoryGameInfo_Cmp CmpFun;
m_gameinfoList.sort(CmpFun);
2.修改list元素的值
list<NOTIFY_RECEIVE_HISTORY_GameInfo_PACKET>::iterator itGameInfo;
for(itGameInfo = m_gameinfoList.begin(); itGameInfo != m_gameinfoList.end(); itGameInfo ++)
{
if ( strcmp(itGameInfo->Gmcode ,GameInfoHistory.Gmcode) == 0 && strcmp(itGameInfo->round , GameInfoHistory.round ) ==0 )
{
NOTIFY_RECEIVE_HISTORY_GameInfo_PACKET *tmp=&(*itGameInfo);
tmp->resbits = GameInfoHistory.resbits;
strncpy(tmp->reslst,GameInfoHistory.reslst,sizeof(GameInfoHistory.reslst));
break;
}
}