Question: Write a C++ function to print the parent and child value of a node at a given index. Start indexing at 0. Function Arguments: head:
Write a C++ function to print the parent and child value of a node at a given index. Start indexing at 0.
Function Arguments:
- head: head of the linked list with at least three values in it
- index: index of a node; print this node's parent and child value separated by a semicolon
The node at index will always have at least one node before it and one node after it. Your function should return the head of the linked list. Do not include endl in your cout statement.
node * PrintBeforeAndAfter(node *head, int index);
The linked list structure:
struct node { int value; node *next; node *prev; };
Example:
Linked list pointed to by head: 4 <-> 7 <-> 8 <-> 22
index = 1
You're function should print:
4;8
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
