[Updated] Goldman Sachs Aptitude Test Questions and Answers
Practice List of TCS Digital Coding Questions !!!
Take 50+ FREE!! Online Data Interpretation Mock test to crack any Exams.
Interview Questions and Answers :: Tavant Technologies

1. How to find the nth node from last in single linklist.

Answer:

void GetNthFromLast(struct node* head, int n)
{
int len = n, i;
struct node *temp = *temp1 = head;

while (temp != NULL)
{
if (len > 0)
{
temp = temp->next;
len--;
continue;
}

temp = temp->next;
temp1 = temp1->next;
}


if (len)
{
printf("\r\n Node in the given Linked list is not enough \r\n");
return;
}

printf ("%d\n", temp1->data);

return;
}

Post Your Answer Here:      Public      Private

Rate This: +4 -0
Report     

Post Your Reply Here:     

Report Error

Report Error

Please Login First Click Here