Write a function GetNth( ) that takes a linked list and an integer index and returns the data value stored in the node at that index position. GetNth() uses the C numbering convention that the first node is index 0, the second is index 1, … and so on. So for the list {42, 13, 666} GetNth() with index 1 should return 13. The index should be in the range [0..length-1]. If it is not, GetNth() should print an error.
int GetNth(struct node* head, int index)
Flatten a multilevel linked list
Given a linked list where in addition to the next pointer, each node has a child pointer, which
may or may not point to a separate list. These child lists may have one or more children of
their own, and so on, to produce a multilevel data structure, as shown in below figure. You
are given the head of the first level of the list. Flatten the list so that all the nodes appear in a
single-level linked list. You need to flatten the list in way that all nodes at first level should
come first, then nodes of second level, and so on. Each node is a C struct with the following
definition.
struct list
{
int data
struct list *next;
struct list *child;
}
The above list should be converted to
10 ->5->12->7->11->4->20->13->17 ->6 ->2 ->16 ->9 ->8 ->3->19->15