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
Explain the advantages of using friend classes.
What is one dimensional array in c++?
How to demonstrate the use of a variable?
What are the uses of static class data?
What are the advantages of using friend classes?
What is the importance of mutable keyword?
What is the type of this pointer in c++?
What is an incomplete type in c++?
Write a function that swaps the values of two integers, using int* as the argument type?
Is it possible to have a recursive inline function in c++?
Write about c++ storage classes?
What is enum c++?
How do you differentiate between overloading the prefix and postfix increments?
What is pointer with example?
How many types of scopes are there in c++?