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

What is enum c++?

618


What are the unique features of C++.

574


What are the rules about using an underscore in a c++ identifier?

636


What is Destructor in C++?

640


What do you mean by function overriding & function overloading in c++?

604






What is the use of volatile variable?

602


What is the use of class in c++?

570


Can we use this pointer in a class specific, operator-overloading function for new operator?

619


What is pointer to array in c++?

623


Can a class be static in c++?

573


Differentiate between a pointer and a reference with respect to c++.

699


What does new return if there is insufficient memory to make your new object?

590


Explain selection sorting?

640


What is the purpose of extern storage specifier?

628


What are its advantages and disadvantages of multiple inheritances (virtual inheritance)?

607