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 struct c++?
Please explain the reference variable in c++?
What is c++ & why it is used?
What jobs can you get with a c++ certification?
What would happen on forgetting [], while deallocating an array through new?
Can I make ios apps with c++?
What are the advantages of pointers?
What things would you remember while making an interface?
What happens if a pointer is deleted twice?
What are friend classes? What are advantages of using friend classes?
What is an arraylist c++?
Which bit wise operator is suitable for checking whether a particular bit is on or off?
What is a rooted hierarchy?
How to get the current position of the file pointer?
can any one help to find a specific string between html tags
which is changed to a sting..
weather.html looks (for location) is