Second post in the series Back to Basic
Display the Nth Node from the End
void findNfromEnd(int nodeNum){
node *ptr1, *ptr2;
ptr1 = ptr2 = head;
for(int i=0; i< (nodeNum-1) ; i++){
ptr1 = ptr1->next;
}
while(ptr1->next != NULL){
ptr1= ptr1->next;
ptr2 = ptr2->next;
}
cout << "Nth Element from End: " << ptr2->data << endl;
}
Advertisement
Discussion
No comments yet.