Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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.

Answers were Sorted based on User's Feedback



Memory is not a constraint. In a single iteration(NOTE: you can't go back), how will you find ..

Answer / aaptuster

Cant we simply check it using 10 dereferencing.

ptr -> ptr -> ptr -> ptr -> ->ptr and so on...

This could be generalized for n, as we could generate this
command string on the fly and execute the command ..

Is This Answer Correct ?    1 Yes 0 No

Memory is not a constraint. In a single iteration(NOTE: you can't go back), how will you find ..

Answer / ashutosh

Assume the list is a circular one (implemented by pos%10).
So, when you are iterating, you are going round and round in
a circle. When you reach the end, you just have to go back
exactly 10 items. By going back here means accessing the
element 10 position prior to the current one, which is
implemented by (pos-10)%10

Since, it's a circular array as assumed, you have always
access it by doing pos%10 or (pos-10)%10.

NOTE: The value of pos has always been incremented and never
decremented or set to zero.

Is This Answer Correct ?    2 Yes 2 No

Memory is not a constraint. In a single iteration(NOTE: you can't go back), how will you find ..

Answer / anon

Have two pointers p1 and p2.p1 points to the first node in the linked list.p2 to the tenth node.Now move both the pointer togther till p2->link = NULL.P1 is pointing to the 10th node from the last

Is This Answer Correct ?    1 Yes 1 No

Memory is not a constraint. In a single iteration(NOTE: you can't go back), how will you find ..

Answer / mayank pathak

Maintain a queue with ten elements. As u encounter a new
element in the linked list dequeue one element and enqueue
this new element. When the link list is fully scanned the
first element of the queue would be the 10th last element.

Is This Answer Correct ?    0 Yes 0 No

Memory is not a constraint. In a single iteration(NOTE: you can't go back), how will you find ..

Answer / dark knight

1-TAKE TWO POINTERS
2-ITERATE 1 POINTER IN THE LIST UP TO THE 10th POSITION FROM STARTING
3-INITIALLY----2nd POINTER IS AT THE HEAD NODE .
4-NOW INCREEMENT both POINTER TO THE NEXT POTISION SUCH THAT THE
1st pointer reaches end .
5--2ND POINTER IS THE REQUIRED NODE

Is This Answer Correct ?    0 Yes 0 No

Memory is not a constraint. In a single iteration(NOTE: you can't go back), how will you find ..

Answer / 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

More C++ General Interview Questions

What is while loops?

0 Answers  


What are the benefits of operator overloading?

0 Answers  


why all c++ program must have default constructor?

6 Answers   IBM,


sir there is some problem with nokia5130c-2,when we are trying to upload movies from net then there is a error occurred"FORMAT NOT SUPPORTED" bt its all ready in 3gp format.please tell me what i do now?

2 Answers   Nokia,


What is difference between shallow copy and deep copy? Which is default?

1 Answers  


make a middle node of doubly linklist to the top of the list

1 Answers  


Why namespace is used in c++?

0 Answers  


How size of a class can be calulated?

2 Answers  


What does I ++ mean in c++?

0 Answers  


Describe public access specifiers?

0 Answers  


Adobe Interview & Adobe Placement Paper

1 Answers   Adobe,


What is rvalue?

0 Answers  


Categories