Page 1 of 1

Hi, i need to dynamically create and return a head node. there is only 1 and only one head node in the list. set both th

Posted: Sat Nov 27, 2021 10:30 am
by answerhappygod
Hi, i need to dynamically create and return a head node. there
is only 1 and only one head node in the list. set both the
prev and next pointers to nullptr. u are given a previous (ie.
Car*prev )and next pointer ( ie. Car*next)in a struct named
Car. I would like to know how to create that function. My method is
to create a new node, which is called Car*head=new Car, then
head->next and head ->prev both equals to nullptr, then i
assign the data to the head, and return it. But it gives me memory
leak, pls help.