Question: Write a C++ function to change the value of a node at the beginning of a linked list. Your function takes two arguments - the
Write a C++ function to change the value of a node at the beginning of a linked list.
Your function takes two arguments - the head of the linked list and the value num to which you change the head node's value. The list has at least one value in it.
Your function should modify the head of the linked list to have the new value.
Example:
Initial List: 4->2->3, key = 5
List After Function Call: 5->2->3
void ChangeValue(node*& head, int key);
The linked list structure:
struct node { int key; node *next; };
For example:
| Test | Result |
|---|---|
// Linked list before function call: 5->3->2->4 // ChangeValue(head, 2); // Linked list after function call: 2->3->2->4 | After calling your function, the list is 2->3->2->4 |
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
