About the node* data type

void insertInmiddle(int d,int p,Nodehead){
if(head==NULL || p==0){
insertAthead(d,head);
return;
}
else if(p>length(head)){
insertAttail(head,d);
}
else{
//take p-1 jumps
int jump=1;
Node
temp=head;
while(jump<=p-1){
temp=temp->next;
jump++;
}

    //create a new node
    Node*n =new Node(d)


}

}

IN this insert at middle function why do we keep using new keyword Node(int d) as defined is a parameterised constructor we could have jusst called it .
Why are we using new??

@Gautampriyadarshi new is used to allocate memory to the pointer n

you could also have done Node n(d);
but then to access the address you need to use &n.
So just for ease of writing we directly create a pointer and allocate memory to it using new keyword.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.