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.
I think I found quite nice soution - no recursion, no arrays. We iterate only once through whole list.
int GetNode(Node *head,int positionFromTail)
{
int index = 0;
Node* current = head;
Node* result = head;
while(current!=NULL)
{
current=current->next;
if (index++>positionFromTail)
{
result=result->next;
}
}
return result->data;
}
Get Node Value
You are viewing a single comment's thread. Return to all comments →
Hi,
I think I found quite nice soution - no recursion, no arrays. We iterate only once through whole list.