Answer should look slimair to this format l = p ->left; //pointer l now points t
ID: 3874477 • Letter: A
Question
Answer should look slimair to this format
l = p ->left; //pointer l now points to the previous node of p
q -> left = l;
q -> right = p;
l -> right = q;
p -> left = q;
1. Write a C++ code to insert a node q on the right of the doubly linked node p in the given double linked list. (Each node has three members: data that contains the information, right and left members contain pointers to the nodes on either side. Ex. p->left represents the address of the node to the left of node p) DlistExplanation / Answer
Given below is the c++ code to insert q in a doubly linked list. 4 links need to be established when q is inserted, 2 on right and 2 on left. hope it helps
r = q->right; //r now points to the next node of p
//set up 2 links on right side of q
q->right = r; //set q's next to r
r->left = q; //set r's previous to q
//set up 2 links on left side of q
p->right = q; //p's next is q
q->left = p // q's left is p