I have 2 codes. (that I had read in one book). the explanation under each code is true (because my book say that !!!). But in my thinking, if one code is true, so the other will be wrong. (wrong mean it will not have result same with the explanation).
p=l.pHead; l.pHead=p->pNext; p->pNext=NULL; //t[B][/B]his action will take p is the first node of Pointer l, after that, Pointer l will be the after value //For example: Pointer l is ABCD //After this action:p=ABCD; l=ABCD; //After that: p=A<NULL> l=BCD
l.pHead=l1.pHead;l1.pTail->pNext=X; //X is other pointer //This action will connect 2 pointer l1 and X to new pointer l.
In my opinion, if second code is True, when you change l1 pointer (l1.pTail->pNext=X), It mean you change l Pointer, too.
So, in first code, l depend on p (l.pHead=p->pNext), so when you "change p, it mean you change l, too" So, when p.pNext=NULL, It mean
l.pHead=p.pNext; p.pNext=NULL; Thus, l.pHead=NULL;
so: L will be A, not ABCD.
So, Who knows what am I wrong, please answer to me, please.
thanks a lot :)
Edited 5 Years Ago by hqt: n/a