A .For a linked list add the given node to the front of the list. (It is doubly
ID: 3544682 • Letter: A
Question
A .For a linked list add the given node to the front of the list. (It is doubly linked)
void pushNode (node* head, node node){
//Complete
}
B. Insert the given node after the node prevNode into the list. If the prevNode is NULL then insert the node at the front of the list. (It is doubly linked)
void insertNode (node* head, node prevNode, node insertingNode){
//Complete
}
C. Evict the node from the list without freeing its memory. (It is doubly linked)
void evictNode (node* head, node node){
//Complete
}
Explanation / Answer
//A .For a linked list add the given node to the front of the list. (It is doubly linked)
void pushNode(node* head,node nodeToInsert)
{
head->previous = nodeToInsert;
nodeToInsert->next = head;
nodeToInsert->previous = NULL;
head = nodeToInsert;
}
//B. Insert the given node after the node prevNode into the list. If the prevNode is NULL then insert the node at the front of the list. (It is doubly linked)
void insertNode (node* head, node prevNode, node insertingNode){
if(prevNode == NULL)
{
pushNode(head,prevNode);
}
else
{
insertingNode->next = prevNode->next;
(prevNode->next)->previous = insertingNode;
insertingNode->previous = prevNode;
prevNode->next = insertingNode;
}
}
//C. Evict the node from the list without freeing its memory. (It is doubly linked)
void evictNode (node* head, node nodeToRemove){
if(head == nodeToRemove)
{
head->=head->next;
head->previous = NULL;
}
else
{
node *tempPreviousNode,*tempNextNode;
tempPreviousNode=nodeToRemove->previous;
tempNextNode=nodeToRemove->next;
tempPreviousNode->next =tempNextNode;
tempNextNode->previous = tempPreviousNode
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.