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
What is enum c++?
What are the unique features of C++.
What are the rules about using an underscore in a c++ identifier?
What is Destructor in C++?
What do you mean by function overriding & function overloading in c++?
What is the use of volatile variable?
What is the use of class in c++?
Can we use this pointer in a class specific, operator-overloading function for new operator?
What is pointer to array in c++?
Can a class be static in c++?
Differentiate between a pointer and a reference with respect to c++.
What does new return if there is insufficient memory to make your new object?
Explain selection sorting?
What is the purpose of extern storage specifier?
What are its advantages and disadvantages of multiple inheritances (virtual inheritance)?