+ 2

Why is a temporary node important while deleting a head node in a singly linked list?

23rd May 2018, 4:30 PM
Mamuya, Gilbert .W
Mamuya, Gilbert .W - avatar
6 Answers
+ 2
You have to copy adress of old head (for delete) set old second node like new head node and remove old head node (using stored reference)... There isnt trace of temporary node in execution... What are you mean?
23rd May 2018, 4:34 PM
KrOW
KrOW - avatar
+ 3
thanks all, i have clearly understand!!!.
23rd May 2018, 9:25 PM
Mamuya, Gilbert .W
Mamuya, Gilbert .W - avatar
+ 2
thanks, but how do you set the old second node as the head node?
23rd May 2018, 5:07 PM
Mamuya, Gilbert .W
Mamuya, Gilbert .W - avatar
+ 1
At example: struct Node{ Node* next; ....... }; class LinkedList{ private: Node* head; ...... public: void popBack(){ if(this->head){ if(this->head->next){ Node* oldHead= head; this->head= oldHead->next; ...... }else{ this->head= NULL; } } } };
23rd May 2018, 5:30 PM
KrOW
KrOW - avatar
+ 1
Futhermore what that怌ļ¼Øļ¼”ļ¼°ļ¼°ļ¼¹ ļ¼“ļ¼Æ ļ¼Øļ¼„ļ¼¬ļ¼°ć€sayed i want precise that you have need to store reference to old node and not copy it
23rd May 2018, 5:52 PM
KrOW
KrOW - avatar
+ 1
You are welcome šŸ‘šŸ‘šŸ‘
23rd May 2018, 9:33 PM
KrOW
KrOW - avatar