You are viewing a single comment's thread. Return to all comments →
CPP SOLUTION
int getNode(SinglyLinkedListNode* llist, int positionFromTail) { SinglyLinkedListNode* temp = llist; SinglyLinkedListNode* temp2 = llist; int count = 0; while(temp != NULL){ temp =temp->next; count++; } int index = count - positionFromTail; count = 1; while(temp2 != NULL){ if(count == index){ return temp2->data; } count++; temp2 = temp2->next; } return -1;
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 →
CPP SOLUTION