We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
int GetNode(Node *head, int positionFromTail)
{
int data;
if (head->next == NULL) {
// store the position in the data variable
data = head->data;
head->data = 0;
// return the data
return data;
}
data = GetNode(head->next, positionFromTail);
if (head->next->data == positionFromTail) {
head->data = head->next->data;
return data;
}
else {
data = head->data;
head->data = head->next->data + 1;
return data;
}
}
Get Node Value
You are viewing a single comment's thread. Return to all comments →
Simple and elegant answer!
Here's a recursive solution just for giggles: