?? mtnodelist.cpp
字號:
#include "stdafx.h"
#include "MTNodeList.h"
CMTNodeList::CMTNodeList()
{
m_pSentBegin=NULL;
m_pSentEnd=NULL;
m_nTopListSize=0;
m_nCurrPos=0;
m_ppTopList=NULL;
}
CMTNodeList::~CMTNodeList()
{
FreeThis();
}
CMTNode* CMTNodeList::GetHead()
{
return m_pSentBegin;
}
CMTNode* CMTNodeList::GetTail()
{
return m_pSentEnd;
}
void CMTNodeList::RemoveHead()
{
if ( m_pSentBegin == NULL )
return;
else
{
CMTNode* m_pSentBeginBak=m_pSentBegin->m_pListNext;
FreeTree(m_pSentBegin);
m_pSentBegin=m_pSentBeginBak;
m_pSentBegin->m_pListPrev=NULL;
}
}
void CMTNodeList::RemoveTail()
{
if ( m_pSentEnd == NULL )
return;
else
{
CMTNode* m_pSentEndBak=m_pSentEnd->m_pListPrev;
FreeTree(m_pSentEndBak);
if ( m_pSentEndBak == NULL )
{
m_pSentEnd=NULL;
m_pSentBegin=NULL;
}
else
{
m_pSentEnd=m_pSentEndBak;
m_pSentEnd->m_pListNext=NULL;
}
}
}
void CMTNodeList::AddHead(CMTNode* pNode)
{
if ( m_pSentBegin == NULL )
{
m_pSentBegin=m_pSentEnd=pNode;
}
else
{
pNode->m_pListNext=m_pSentBegin;
m_pSentBegin->m_pListPrev=pNode;
m_pSentBegin=pNode;
}
}
void CMTNodeList::AddTail(CMTNode* pNode)
{
if ( m_pSentBegin == NULL )
{
m_pSentBegin=m_pSentEnd=pNode;
}
else
{
pNode->m_pListPrev=m_pSentEnd;
m_pSentEnd->m_pListNext=pNode;
m_pSentEnd=pNode;
}
}
void CMTNodeList::RemoveAll()
{
CMTNode* pCurrNode;
CMTNode* pBackNode;
pCurrNode=m_pSentBegin;
while(pCurrNode!=NULL)
{
pBackNode=pCurrNode->m_pListNext;
FreeTree(pCurrNode);
pCurrNode=pBackNode;
}
}
void CMTNodeList::InsertBefore(CMTNode* pPosNode,CMTNode* pNode)
{
//NoOver
}
void CMTNodeList::InsertAfter(CMTNode* pPosNode,CMTNode* pNode)
{
//NoOver
}
int CMTNodeList::GetCount()
{
//NoOver
return 1;
}
BOOL CMTNodeList::IsEmpty()
{
//NoOver
return TRUE;
}
void CMTNodeList::DeleteNode(CMTNode* pNode)
{
if ( pNode == m_pSentBegin &&
pNode == m_pSentEnd )
{
m_pSentBegin=m_pSentEnd=NULL;
}
else if ( pNode == m_pSentBegin )
{
m_pSentBegin=pNode->m_pListNext;
pNode->m_pListNext->m_pListPrev=m_pSentBegin;
}
else if ( pNode == m_pSentEnd )
{
pNode->m_pListPrev->m_pListNext=m_pSentEnd;
m_pSentEnd=pNode->m_pListPrev;
}
else
{
pNode->m_pListPrev->m_pListNext=pNode->m_pListNext;
pNode->m_pListNext->m_pListPrev=pNode->m_pListPrev;
}
FreeTree(pNode);
pNode=NULL;
}
void CMTNodeList::FreeTree(CMTNode*& pNode)
{
if ( pNode ==NULL )
{
return;
}
CMTNode* pNodeA;
CMTNode* pNodeB;
pNodeA=pNode->m_pChild;
while( pNodeA != NULL )
{
pNodeB=pNodeA->m_pTreeNext;
FreeTree(pNodeA);
pNodeA=pNodeB;
}
delete pNode;
pNode=NULL;
}
CMTNode* CMTNodeList::GetScanNode(CMTNode* pNode,int nNodeNo)
//以pNode為當前節點,返回第nNodeNo節點
{
CMTNode* pNodeScan;
pNodeScan=pNode;
if ( nNodeNo > 0 )
{
for ( int Loop=0;Loop<nNodeNo;Loop++)
{
if ( pNodeScan == NULL )
return NULL;
pNodeScan=pNodeScan->m_pListNext;
}
return pNodeScan;
}
else if ( nNodeNo < 0 )
{
for ( int Loop=0;Loop<abs(nNodeNo);Loop++)
{
if ( pNodeScan == NULL )
return NULL;
pNodeScan=pNodeScan->m_pListPrev;
}
return pNodeScan;
}
else
return pNode;
return NULL;
}
void CMTNodeList::FreeThis()
{
if ( m_pSentBegin != NULL )
RemoveAll();
m_pSentBegin=NULL;
m_pSentEnd=NULL;
m_pSentBegin=NULL;
m_pSentEnd=NULL;
m_nCurrPos=-1;
delete m_ppTopList;
m_ppTopList=NULL;
}
CMTNode* CMTNodeList::GetCurrentNode()
{
if ( m_nCurrPos >= m_nTopListSize ||
m_nCurrPos<0 )
return NULL;
else
return (CMTNode*)m_ppTopList[m_nCurrPos];
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -