熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> 數據結構 >> 正文

有兩個雙向循環鏈表A,B,知道其頭指針為:pHeadA,pHeadB,請寫一函數將兩鏈表中data

2022-06-13   來源: 數據結構 

有雙向循環鏈表結點定義為
struct node
{ int data;
struct node *front*next;
};
有兩個雙向循環鏈表AB知道其頭指針為pHeadApHeadB請寫一函數將兩鏈表中data值相同的結點刪除
BOOL DeteleNode(Node *pHeader DataType Value)
{
if (pHeader == NULL) return;
BOOL bRet = FALSE;
Node *pNode = pHead;
while (pNode != NULL)
{
if (pNode>data == Value)
{
if (pNode>front == NULL)
{
pHeader = pNode>next;
pHeader>front = NULL;
}
else
{
if (pNode>next != NULL)
{
pNode>next>front = pNode>front;
}
pNode>front>next = pNode>next;
}
Node *pNextNode = pNode>next;
delete pNode;
pNode = pNextNode;
bRet = TRUE;
//不要break或return 刪除所有
}
else
{
pNode = pNode>next;
}
}
return bRet;
}
void DE(Node *pHeadA Node *pHeadB)
{
if (pHeadA == NULL || pHeadB == NULL)
{
return;
}
Node *pNode = pHeadA;
while (pNode != NULL)
{
if (DeteleNode(pHeadB pNode>data))
{
if (pNode>front == NULL)
{
pHeadA = pNode>next;
pHeadA>front = NULL;
}
else
{
pNode>front>next = pNode>next;
if (pNode>next != NULL)
{
pNode>next>front = pNode>front;
}
}
Node *pNextNode = pNode>next;
delete pNode;
pNode = pNextNode;
}
else
{
pNode = pNode>next;
}
}
}


From:http://tw.wingwit.com/Article/program/sjjg/201405/30940.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.