Question: 1. Answer the C++ function delete_val() that deletes the node containing a given value from a singly-linked list with a dummy head node. Assume the
1. Answer the C++ function delete_val() that deletes the node containing a given value from a singly-linked list with a dummy head node. Assume the following Node class declaration for nodes: class Node { public: int data; Node * next; } The function returns if the list is empty or it does not contain the value. If the value is in the list the function should delete the node after adjusting the links in the linked list. void delete_val(Node * list, int val) Node *p=list; // pointer to be used to traverse the list
// Check if list is empty.
// Note that the list has a dummy head node
Answer:
// Traverse the list to find the node with value val
Answer
// If the value does not exist in the list simply return
Answer:
// Or remove the node from the list
Answer:
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
