kikit
9/1/2016 - 4:22 PM

Get Node Value - Hackerrank

Get Node Value - Hackerrank

int GetNode(Node *head,int positionFromTail)
{
    Node *current = head;
    int count = 0;
    while(current != NULL){
        count++;
        current = current->next;
    }
    int position = count - positionFromTail;
    current = head;
    while(--position > 0){
        current = current->next;
    }
    return current->data;
}