0
Can we pass linked list inside function?
Why below code has not proper working of display function from compare function? https://code.sololearn.com/cPyG6dgpwd3W/?ref=app
1 Odpowiedź
+ 2
In the display function, the code accesses the value using pHeadNode. So after a call to display, pHeadNode will point to null and the list is, therefore, lost in memory. Thus, successive calls to display do not work.
The solution is to simply make a copy of pHeadNode and iterate over the list using the copy node.
clsNode* cpy = pHeadNode;
while(cpy!=NULL)
{
cout << cpy->intData;
cout << endl;
cpy = cpy->pNext;
}