Memory is not a constraint. In a single iteration(NOTE: you
can't go back), how will you find out the 10th last
node/item in a linked list.

Answer Posted / ashutosh

List *nodes[10]; //asked 10th last, so, only 10 items
int pos = 0;

List *ptr = &FirstNode

while(ptr)
{
nodes[(pos%10)] = ptr;
pos++;
ptr = ptr->next;
}
if(pos>=10)
{
printf("Tenth last element is %d",nodes[(pos-10)%10]->data);
}
else
{
printf("There doesn't exist any 1oth last element");
}

Is This Answer Correct ?    13 Yes 17 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain the advantages of using friend classes.

831


What is one dimensional array in c++?

814


How to demonstrate the use of a variable?

842


What are the uses of static class data?

866


What are the advantages of using friend classes?

866


What is the importance of mutable keyword?

790


What is the type of this pointer in c++?

814


What is an incomplete type in c++?

961


Write a function that swaps the values of two integers, using int* as the argument type?

784


Is it possible to have a recursive inline function in c++?

757


Write about c++ storage classes?

963


What is enum c++?

864


How do you differentiate between overloading the prefix and postfix increments?

804


What is pointer with example?

742


How many types of scopes are there in c++?

785