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.

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

Write a program in c++ to print the numbers from n to n2 except 5 and its multiples

2493


What is data types c++?

1027


Are strings immutable in c++?

1166


Difference between an inspector and a mutator

1344


Is multimap sorted c++?

1014


What are the advantages of using pointers in a program?

1146


Write a program to find the Fibonacci series recursively.

1075


Is c the same as c++?

1018


Can you overload the operator+ for short integers?

1045


Is c++ built on c?

1038


Describe the syntax of single inheritance in C++?

1082


What is c++ good for?

1067


Why do we need runtime polymorphism in c++?

1032


Should I learn c or c++ first?

1131


What is the basic concept of c++?

1015