Question: Write a C+function to add a node to the beginning of a linked list. Your function takes two arguments-the head of the linked list and

Write a C+function to add a node to the beginning of a linked list. Your function takes two arguments-the head of the linked list and the value key to be added Note that the list may be empty! Your function should modify the head of the linked list to point to the new node, and set the new node to point to the rest of the list. If the rest of the list is empty, the new node points to null Example: nitial List: 42->3, key-5 List After Function Call: 5->4->2->3 oid AddNode(Node*& head, double key) The linked list structure: struct Node double val node *next bi For example: Test Result After calling your function, the list is 5.1->3.1->2.2->4.7 // head-4.7 // AddNode(head, 2.2) // AddNode (head, 3.1) //AddNode (head, 5.1)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
