⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mtnodelist.cpp

📁 计算机英汉机器翻译系统中的英语词性标注方法实现
💻 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 + -