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...

Implement a function that returns the 5th element from the
end in a singly linked list of integers in one pass.

Answer Posted / gbohrn

int return_fifth_from_end()
{
int i,j;
struct node *p,*q;
*p=HEAD_NODE;
for(i=0;i<4;i++)//will make p point to the 5th element
{
p=p->next;
if(p==NULL)
{
printf("List has less than 5 elements");
}
}
q=HEAD_NODE;
while(p->next!=NULL)
{
p=p->next;
q=q->next;
}
return(q->Value);
}

Is This Answer Correct ?    5 Yes 6 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between declaring a variable by constant keyword and #define ing that variable?

3285


What is dynamic variable in c?

986


Write a program to find the biggest number of three numbers in c?

1005


Is c compiled or interpreted?

1129


What is the use of the function in c?

971


Where static variables are stored in memory in c?

948


Which one would you prefer - a macro or a function?

1034


What are the types of bitwise operator?

1048


Explain what is the difference between functions getch() and getche()?

990


what is a NULL Pointer? Whether it is same as an uninitialized pointer?

1212


Where are some collections of useful code fragments and examples?

1107


in linking some of os executables are linking name some of them

2075


When should a type cast not be used?

1005


What is difference between Structure and Unions?

1185


What are inbuilt functions in c?

983