You are viewing a single comment's thread. Return to all comments →
Salcio, your solution is excellent, but you can simplify the code even further by not maintaining a separate "current" pointer.
int GetNode(Node *head,int positionFromTail) { Node* tortoise = head; int index = 0; while (head->next) { head = head->next; if (++index > positionFromTail) { tortoise = tortoise->next; } } return tortoise->data; }
Seems like cookies are disabled on this browser, please enable them to open this website
Get Node Value
You are viewing a single comment's thread. Return to all comments →
Salcio, your solution is excellent, but you can simplify the code even further by not maintaining a separate "current" pointer.