Question: Given a head node of singly linked list, write a function to double the value in each node. A new node should be inserted after
Given a head node of singly linked list, write a function to double the value in each node. A new node should be inserted after each node with the value equal to double its previous. The function should return the head node after inserting the necessary nodes. (bold is what is given)
struct Node{
int value;
Node *next;
}
Node *DoublePrevious(Node *head)
Examples:
Given linked list : 1 -> 2 -> 3 -> nullptr
Output : 1 -> 2 -> 2 -> 4 -> 3 -> 6 -> nullptr
Given linked list : 5 -> 7 -> 9 -> nullptr
Output : 5 -> 10 -> 7 -> 14 -> 9 -> 18 -> nullptr
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
