[VC] 队列类
作者:互联网
MFC 里有CList类具有链表,队列功能,通过封装可做成FIFO,FILO队列.
在多线程中应用可结合互斥锁使用.
例子:
=========FIFO (First In First Out)===============
CList<CString> g_mList;
void Queue_FIFO_Push(CString strIn)
{
g_mList.AddTail( strIn ); //从尾部插入数据FIFO
}
BOOL Queue_FIFO_Pop(CString &strOut)
{
POSITION posi;
BOOL ret = FALSE;
posi = g_mList.GetTailPosition();
if (posi !=NULL)
{
ret = TRUE;
strOut=g_mList.GetAt(posi);
g_mList.RemoveTail();//删除最后的数据
}
return ret;
}
=========FILO (First In Last Out)===============
CList<CString> g_mList;
void Queue_FILO_Push(CString strIn)
{
g_mList.AddHead( strIn ); //从头部插入数据FILO
}
BOOL Queue_FILO_Pop(CString &strOut)
{
POSITION posi;
BOOL ret = FALSE;
posi = g_mList.GetHeadPosition();
if (posi !=NULL)
{
ret = TRUE;
strOut=g_mList.GetAt(posi);
g_mList.RemoveHead();//删除最前的数据
}
return ret;
}
标签:VC,posi,队列,FIFO,mList,ret,FILO,strOut 来源: https://blog.csdn.net/wabil/article/details/118997420