【发布时间】:2015-10-31 16:23:35
【问题描述】:
我试图在另一个列表的末尾插入一个列表 使用此代码:
typedef struct Element
{
int vKey;
char vInfo[30];
struct Element *pNext;
} tsElement;
typedef struct
{
tsElemento *pFirst;
int vLength;
} tsLDSE;
void Unir(tsLDSE *pListIn, tsLDSE *pListOut)
{
tsElement *pElementOut;
pElementOut = pListOut->pFirst;
while (pElementOut != NULL)
{
pElementOut = pElemenoOut->pNext;
}
pElementOut = pListIn->pFirst;
pListOut->vLength = pListOut->vLength + pListIn->vLength ;
}
我检查了打印地址,pElementoOut 确实是第一个列表的末尾并且指向 NULL,然后它接收第二个列表的第一个地址,但是当我打印它时它只打印第一个列表,我可以不知道为什么。
【问题讨论】:
-
你需要
pElemenoOut->pNext = pListIn->pFirst之前pElemenoOut是NULL。 -
谢谢,它成功了,但我不明白为什么,因为 pElementOut 是 pPrevious->pNext 并且是 null 为什么我不能只是 pElementOut = pListIn->First
-
pElementOut是与pPrevious->pNext具有相同值 的局部变量,但pElementOut不是pPrevious->pNext。 -
链接,列出所以没有调试,所以 DCV。