Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Exercise Show a code snippet for finding where to insert a new node in a doubly

ID: 3586508 • Letter: E

Question

Exercise

Show a code snippet for finding where to insert a new node in a doubly linked ordered list which uses a header and a footer node.

Assume:

list->pHeader points to a header node.

list->pFooter points to a footer node.

pNew already has been allocated and contains the element.

pPrecedes is used to point to the node that precedes where we want pNew inserted.

*program is in c*

Exercise

Show a code snippet for finding where to insert a new node in a doubly linked ordered list which uses a header and a footer node.

Assume:

list->pHeader points to a header node.

list->pFooter points to a footer node.

pNew already has been allocated and contains the element.

pPrecedes is used to point to the node that precedes where we want pNew inserted.

*program is in c*

Explanation / Answer

void insert(struct node **Head, struct node **Foot, struct node *pNew, struct node *pPrecedes)
{
struct node *pHeader = *Head, *pFooter = *Foot;
  
pNew->next = pPrecedes->next;
pNew->prev = pPrecedes;
  
if(pPrecedes!=NULL)
pPrecedes->next = pNew;
else
pHeader = pNew;
  
if(pPrecedes->next!=NULL)
pPrecedes->next->prev = pNew;
else
pFooter = pNew;
  
*Head = pHeader;
*Foot = pFooter;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote