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

Is map sorted c++?

517


What is the difference between #define debug 0 and #undef debug?

641


Is c++ a pure oop language?

598


What is pointer with example?

560


What is std :: endl?

596






What is abstraction c++?

587


Define basic type of variable used for a different condition in C++?

662


Differentiate between a copy constructor and an overloaded assignment operator.

641


Explain differences between alloc() and free()?

578


what is Member Functions in Classes?

617


What are the new features that iso/ansi c++ has added to original c++ specifications?

583


How the delete operator differs from the delete[]operator?

642


Write a function to find the nth item from the end of a linked list in a single pass.

567


What is a dynamic binding in c++?

528


What number of digits that can be accuratly stored in a float (based on the IEEE Standard 754)? a) 6 b) 38 c) An unlimited number

781