typedef struct SingList
{
int nData;
struct SingList *pNext;
}SingnNode,*pSingnNode;
typedef struct LoopList
{
int nData;
struct LoopList *pLeft,*pRight;
}LoopNode,*pLoopNode;
void CLoopList::InestMyList(pLoopNode pHead,int nData,int nNum)
{
pLoopNode pTemp,pNewNode;
if ((pTemp = SerachMyList(pHead,nData)) == NULL)
{
strErrMsg.Format(_T("Can find the node :[%d]!"),nNum);
return;
}
if ((pNewNode = new LoopNode) == NULL)
{
strErrMsg.Format(_T("Can not new memory!"));
return;
}
pNewNode->pLeft = pTemp->pLeft;
pNewNode->pRight = pTemp;
pTemp->pLeft->pRight = pNewNode;
pTemp->pLeft = pNewNode;
}
void CLoopList::DelMyList(pLoopNode pHead,int nData)
{
pLoopNode pTemp;
if ((pTemp = SerachMyList(pHead,nData)) == NULL)
{
strErrMsg.Format(_T("Can find the node :[%d]!"),nData);
return;
}
pTemp->pRight->pLeft = pTemp->pLeft;
pTemp->pLeft->pRight = pTemp->pRight;
delete pTemp;
}
void CLoopList::PrintMyList(pLoopNode pHead)
{
int nOutData;
pLoopNode pTemp;
pTemp = pHead->pRight;
if (pTemp == pHead)
{
strErrMsg.Format(_T("That ia a empty LoopNode!"));
return;
}
while(pTemp != pHead)
{
nOutData = pTemp->nData;
pTemp = pTemp->pRight;
}
}
pLoopNode CLoopList::SerachMyList(pLoopNode pHead,int nData)
{
pLoopNode pTemp;
pTemp = pHead->pRight;
while(pTemp != pHead)
{
if (nData == pTemp->nData)
{
return pTemp;
}
else
{
pTemp = pTemp->pRight;;
}
}
return NULL;
}
pLoopNode CLoopList::CreateMyList(int nNum)
{
pLoopNode pHead,pTemp,pNewNode;
if ((pHead = new LoopNode) == NULL)
{
strErrMsg.Format(_T("Can not new memory!"));
return NULL;
}
pHead->nData = 0;
pHead->pLeft = NULL;
pHead->pRight= NULL;
pTemp = pHead;
for (int i = 0; i < nNum; i++)
{
if ((pNewNode = new LoopNode) == NULL)
{
strErrMsg.Format(_T("Can not new memory!"));
return NULL;
}
pNewNode->nData = i + 1;
pNewNode->pLeft = pTemp;
pNewNode->pRight = NULL;
pTemp = pNewNode;
}
pTemp->pRight = pHead;
pHead->pLeft = pNewNode;
return pHead;
}