Question: Write a C++ function to delete a node to the beginning of a linked list. Your function takes one argument - the head of the

Write a C++ function to delete a node to the beginning of a linked list.

Your function takes one argument - the head of the linked list with at least one node in it.

Your function should modify the head of the linked list to point to the new head node. If the list is empty after deleting, head points to null.

Example:

Initial List: 4->2->3

List After Function Call: 2->3

void Delete(Node*& head); 

The linked list structure:

struct Node { int key; node *next; }; 

For example:

Test Result
// head points to linked list 5->3->2->4 // Delete(head); // head points to linked list 3->2->4 
After calling your function, the list is 3->2->4 

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!