Question: Write a C++ function to add a node to a doubly linked list after a given node index. Start indexing at 0. Function Arguments: head:

Write a C++ function to add a node to a doubly linked list after a given node index. Start indexing at 0.

Function Arguments:

head: head of the doubly linked list

value: value to be added to linked list

indexIn: node index after which to add the value

The linked list has at least ( indexIn + 1 ) values in it. Your function should return the head of the linked list.

node * AddAfterIndex(node *head, int value, int indexIn); 

The linked list structure:

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

For example:

Test Result
//-1 <-> 0 <-> 99 <-> 0 //add value 22 after indexIn = 2 
-1 <-> 0 <-> 99 <-> 22 <-> 0 

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!