+ 2
Why is a temporary node important while deleting a head node in a singly linked list?
6 Respuestas
+ 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?
+ 3
thanks all, i have clearly understand!!!.
+ 2
thanks, but how do you set the old second node as the head node?
+ 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;
}
}
}
};
+ 1
Futhermore what that「HAPPY TO HELP」sayed i want precise that you have need to store reference to old node and not copy it
+ 1
You are welcome 👍👍👍